How to generate a PHP soap client code?

2019-01-23 07:56发布

Is there a way to generate a PHP Soap Client from a WSDL file?

I mean something like wsdl.exe or svcutil.exe in .net, that generates code for a class that can be the client of a service, not something like:

$WSDL     = new SOAP_WSDL($wsdl_url); 
$client   = $WSDL->getProxy(); 

My problem is that I want the PHP client to be able the work with a service, even when that service doesn't expose its WSDL.

6条回答
Fickle 薄情
2楼-- · 2019-01-23 08:17

Just to help anyone else who comes across this post and thinks "how the heck do I work w/ this SOAP_WSDL thing?" (like myself)

Open the command line and get to your php directory (I installed XAMPP Lite in this example)

Once in the php directory I ran the pear.bat script. After this I was able to type the following via cmd line

pear -V (provides the version of your install)

pear list

If you type the above and don't see SOAP you need to do the following from the cmd line:

  • pear install Net_DIME-1.0.1

  • pear install Mail_Mime-1.5.2

  • pear install Mail-1.2.0b1

  • pear install SOAP-0.12.0

Now after you install these packages and do another "pear list" you should see SOAP listed.

If so you can include a reference to the php files pulled down inside the pear directory under SOAP.

One example of this path might be C:\xampplite\php\PEAR\SOAP

查看更多
走好不送
3楼-- · 2019-01-23 08:17

I used wsdl2php, a simple PEAR tool; it seems that project is dead, but you can still download the latest version here: http://sourceforge.net/projects/wsdl2php/

It require a development machine with PHP 5 and PEAR, and you have to install it with this PEAR command:

sudo pear install wsdl2php-0.2.1-pear.tgz

After this, you can generate the PHP classes file with this command:

wsdl2php <WSDL_URL>

It generates a main class that extends SoapClient, and many other classed that represent requests, responses, and complex objects, so it is very useful when developing in a IDE with "intellisense" like NetBeans.

查看更多
Lonely孤独者°
4楼-- · 2019-01-23 08:18

I found generator really useful

https://github.com/wsdl2phpgenerator/wsdl2phpgenerator

Instructions (from github) :

  • Download wsdl2phpgenerator-2.3.0.phar from the latest release
  • Run "php wsdl2phpgenerator-2.3.0.phar -i input.wsdl -o tmp/my/directory/wsdl"

Work for web hosted wsdl too

eg

php wsdl2phpgenerator-2.3.0.phar -i http://someurl/input.wsdl -o tmp/my/directory/wsdl
查看更多
\"骚年 ilove
5楼-- · 2019-01-23 08:33

There is an app for this, it's called wsdl2phpgenerator:

http://code.google.com/p/wsdl2phpgenerator/

Run it against a WSDL file and it will generate classes based on the WSDL services.

查看更多
疯言疯语
6楼-- · 2019-01-23 08:35

I've tried to use everething that were listed here.

Found the another choise: https://github.com/mikaelcom/WsdlToPhp

Pluses in comparition with previous:

  • No dependencies. Both for generator and created client.

  • Classes for in and out parameters.

  • Examples of using for created client. It's course not so important. But some times very useful

  • Less of code (In comparision with SOAP_WSDL)

Minuses:

  • Answer and any complex subtype are wrapped to another object that contains technical info.
查看更多
家丑人穷心不美
7楼-- · 2019-01-23 08:36

You can use the method [generateProxyCode] provided in the package SOAP_WSDL (http://pear.php.net/reference/SOAP-0.9.4/SOAP/SOAP_WSDL.html#methodgenerateProxyCode) method instead and save it to a file:

$WSDL     = new SOAP_WSDL($wsdl_url); 
$php      = $WSDL->generateProxyCode();
file_put_contents('wsdl_proxy.php', '<?php ' . $php . ' ?>');

require 'wsdl_proxy.php';
查看更多
登录 后发表回答