php 如何生成PHPsoap客户端代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1656727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to generate a PHP soap client code?
提问by Meidan Alon
Is there a way to generate a PHP Soap Client from a WSDL file?
有没有办法从 WSDL 文件生成 PHP Soap 客户端?
I mean something like wsdl.exeor svcutil.exein .net, that generates code for a class that can be the client of a service, not something like:
我的意思是像.netwsdl.exe或svcutil.exe在 .net 中的东西,它为可以作为服务客户端的类生成代码,而不是类似的东西:
$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.
我的问题是我希望 PHP 客户端能够使用服务,即使该服务不公开其 WSDL。
采纳答案by Greg
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:
您可以使用generateProxyCode包 SOAP_WSDL ( http://pear.php.net/reference/SOAP-0.9.4/SOAP/SOAP_WSDL.html#methodgenerateProxyCode) 方法中提供的方法 [ ]并将其保存到文件中:
$WSDL = new SOAP_WSDL($wsdl_url);
$php = $WSDL->generateProxyCode();
file_put_contents('wsdl_proxy.php', '<?php ' . $php . ' ?>');
require 'wsdl_proxy.php';
回答by aqm
I found generator really useful
我发现发电机真的很有用
https://github.com/wsdl2phpgenerator/wsdl2phpgenerator
https://github.com/wsdl2phpgenerator/wsdl2phpgenerator
Instructions (from github) :
说明(来自github):
- Download wsdl2phpgenerator-2.3.0.pharfrom the latest release
- Run "php wsdl2phpgenerator-2.3.0.phar -i input.wsdl -o tmp/my/directory/wsdl"
- 从最新版本下载wsdl2phpgenerator-2.3.0.phar
- 运行“php wsdl2phpgenerator-2.3.0.phar -i input.wsdl -o tmp/my/directory/wsdl”
Work for web hosted wsdl too
也适用于 Web 托管的 wsdl
eg
例如
php wsdl2phpgenerator-2.3.0.phar -i http://someurl/input.wsdl -o tmp/my/directory/wsdl
回答by Clay Hinson
There is an app for this, it's called wsdl2phpgenerator:
有一个应用程序,它叫做 wsdl2phpgenerator:
http://code.google.com/p/wsdl2phpgenerator/
http://code.google.com/p/wsdl2phpgenerator/
Run it against a WSDL file and it will generate classes based on the WSDL services.
针对 WSDL 文件运行它,它将根据 WSDL 服务生成类。
回答by Toran Billups
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)
只是为了帮助其他人看到这篇文章并认为“我到底是如何使用 SOAP_WSDL 工作的?” (就像我自己)
Open the command line and get to your php directory (I installed XAMPP Lite in this example)
打开命令行并进入你的 php 目录(我在这个例子中安装了 XAMPP Lite)
Once in the php directory I ran the pear.bat script. After this I was able to type the following via cmd line
进入 php 目录后,我运行了 pear.bat 脚本。在此之后,我能够通过 cmd 行键入以下内容
pear -V (provides the version of your install)
pear -V(提供安装版本)
pear list
梨列表
If you type the above and don't see SOAP you need to do the following from the cmd line:
如果您键入以上内容但没有看到 SOAP,则需要从 cmd 行执行以下操作:
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
梨安装 Net_DIME-1.0.1
梨安装Mail_Mime-1.5.2
梨安装 Mail-1.2.0b1
梨安装 SOAP-0.12.0
Now after you install these packages and do another "pear list" you should see SOAP listed.
现在,在您安装这些软件包并执行另一个“梨列表”之后,您应该会看到列出了 SOAP。
If so you can include a reference to the php files pulled down inside the pear directory under SOAP.
如果是这样,您可以在 SOAP 下的 pear 目录中包含对 php 文件的引用。
One example of this path might be C:\xampplite\php\PEAR\SOAP
此路径的一个示例可能是 C:\xampplite\php\PEAR\SOAP
回答by Pisu
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/
我使用了wsdl2php,一个简单的 PEAR 工具;项目似乎已经死了,但你仍然可以在这里下载最新版本: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:
它需要一台带有 PHP 5 和 PEAR 的开发机器,你必须使用这个 PEAR 命令安装它:
sudo pear install wsdl2php-0.2.1-pear.tgz
After this, you can generate the PHP classes file with this command:
之后,您可以使用以下命令生成 PHP 类文件:
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.
它生成一个扩展 SoapClient 的主类,以及许多其他表示请求、响应和复杂对象的类,因此在具有“智能感知”(如 NetBeans)的 IDE 中进行开发时,它非常有用。
回答by Kamil Gareev
I've tried to use everething that were listed here.
我试过使用这里列出的一切。
Found the another choise: https://github.com/mikaelcom/WsdlToPhp
找到了另一个选择:https: //github.com/mikaelcom/WsdlToPhp
Pluses in comparition with previous:
与之前相比的优点:
No dependencies. Both for generator and created client.
Classes for inand outparameters.
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)
没有依赖性。 用于生成器和创建的客户端。
班中和出参数。
用于创建客户端的示例。当然不是那么重要。但有时非常有用
更少的代码(与 SOAP_WSDL 相比)
Minuses:
缺点:
- Answer and any complex subtype are wrapped to another object that contains technical info.
- Answer 和任何复杂的子类型都被包装到另一个包含技术信息的对象中。

