How to generate helper classes and stub code with wsdl2php for a PHP web service?
I have a WSDL generated by WCF and now this WSDL should be used to create a PHP web service. My WSDL contains mappings to custom .NET classes (complexType) and I would need a PHP WSDL tool which can generate the equivalent PHP classes as well as the stub code (server-side generation).
I read that the wsdl2php would be the right tool to do the job so I tried it at the address: (http://labs.wso2.org/wsf/php/wsdl2phptool.php)
It worked partly by creating the stub code but it didn't create any helper classes (function parameters seem to be of type anyType and only one parameter is generated for each function). I have also the script version which I can run with the following kind of command in Windows:
php wsdl2php.php -s http://My.Server.com/MyW开发者_StackOverflow中文版CFService/MyWCFService.svc?wsdl > MyWebService.php
but for some reason it doesn't seem to work as it outputs an empty file. I'm not a PHP expert as I am a .NET developer but I would need to test how our WSDL works with PHP web services (just to see that it's possible to generate PHP code from our WSDL in the same way as in .NET).
I would be grateful if you could give me a simple example of generating helper classes and stub code for a PHP web service.
Thanks! :)
Found the solution! In order to generate helper classes in addition to the stub code with wsdl2php you will need a single WSDL file. The current version (2.1.0) of wsdl2php has difficulties to understand the WSDL generated by WCF. This is due to import tags used in the WCF WSDL (schemas have been imported into the wsdl document and wsdl2php doesn't like this)
After I created a single WCF WSDL by using WCFExtras I managed to generate also helper classes!
"http://wcfextras.codeplex.com/"
"http://weblogs.asp.net/pglavich/archive/2010/03/16/making-wcf-output-a-single-wsdl-file-for-interop-purposes.aspx" (read this first as it's important to specify namespaces correctly or you will encounter problems with WCFExtras)
You can also use T4 templates for generating ServiceProxies and DataContract classes from your Service implementation. I have been developing them for a project of mine, they are released on GitHub including samples:
https://github.com/schaermu/wcf-phpclient-t4
Just in case you want the proxy-generation logic in your .NET solution.
精彩评论