Recently I have been developing web-services for integration of one of our flagship product to other POS software at Meditab Software. My official working platform is PHP and we have been developing web services for communication between our products to internal web applications in the past but it was like "We understand what we speak..!" as we have not been dealing with any external entity during these communications the input parameters used to be simple data-types and for output we understand what we give back using single simple data-type.
When I read requirement specification for the web service which I have developed recently I thought I could finish it in a day or two as I have been developing web-services recently. I went on and started and went into trouble with "complexType" declaration in WSDL. I was having C# example to work with provided by the company which was going to use my webservice. I tried that but the thing is when you use Microsoft ASP.NET platform to develop web services what developer needs to is just expose their method with [WebMethod] attribute and you are done! All hardwork and complex WSDL generation will be done by .NET framework. But when it comes to PHP you gotta deal with WSDL generation and make sure you do it perfectly or else your web-service won't work.
In PHP we have SOAP extension which really helps when we need to develop web services and that's what I have been using previously. But it doesn't help you/me for generating WSDL files and that part we have to bare with. I have searched out google for help but it was difficult to find perfect working example of Web service which takes in and out Complex Data types. Here Complex Data Type means user defined Classes and Arrays. When we work with ASP.NET we just declare it as WebMethod and everything goes smooth, we don't need to worry about WSDL generation and anything else. I tried to use the same WSDL generated from ASP.NET C# example but it didn't worked in my case and won't work for anyone. Here I mean we can get some idea about but direct copy + paste won't work. Because it has to be made in a way that SOAP extension understand that and generate RESPONSE and REQUEST XML in desired way. It took me considerable amount of time to got through the proper WSDL generation and I took almost 4 and 1/2 days to get that project done.
Here I would like to mention that PHP SOAP extension is not well documented and it requires quite a lot of hardwork when we need to deal with complicated Web Services. Although some WSDL generators are available (I am talking about some WSDL generator projects and Zend WSDL generator which comes with Zend Studio), they sometimes don't work perfectly for our requirement.
Here I would like to mention one more thing that eviware soapUI tool helped me for checking that whether my WSDL file is proper or not as ultimately it was supposed to be consumed on some other platform. I even tested it out on PowerBuilder 10.5 as it is actually our company's main product's development platform to make sure it's compatibility.
Even getting web service port on other platform took some considerable amount of time and XML and SOAP namespace nitty-gritty are difficult for newbie to get through. I am lucky I got a chance to develop this project.
I am planning to post proper example post explaining how to deal with PHP and SOAP web-services soon. I would like all readers to share their experiences with me on this blog for this subject.
#1 by Vivek Despande on May 7, 2008 - 3:11 pm
Quote
Currently i m facing the problem of php web service . Actually i m calling php web service in my asp.net application . i am calling one API which returns array of class but when i am calling from it dotnet application it returns null value.
Can you please help me for that.
Thanks
Vivek
#2 by Vivek Despande on May 7, 2008 - 3:13 pm
Quote
Hello All,
I am calling third party php webservice in my asp.net application.
LocalhostXYZ srvLogin = new Localhost.XYZ();
Localhost.LogonResponseArray arryObj = new LogonResponseArray();
arryObj = srvLogin.logon(“abc”, “pqr”, “xyz”);
Where logon() is API from Php Web service.
Return type of logon() method is LogonResponseArray class which is of array type.
I am facing one problem that arryObj returns null value.
So can any one tell me how can i get proper value.
Thanks
Vivek Deshpande
#3 by Dharmavirsinh Jhala on May 7, 2008 - 11:45 pm
Quote
Hi Vivek,
Do you have php code for that service or could you just publish WSDL for that?
As the reason being it is possible that SOAP version conflict or xml specification issue with that.
If that third party extension is using PHP SOAP extension then lot of things depends on WSDL specification, as PHP’s SOAP extension (SoapServer) will read the WSDL and parse response XML envelope in that manner.
For that you can do at least one thing, try creating PHP SoapClient and test it with PHP Client and see do you get proper result or not?
Here is the possible sample code for creating Test Client in PHP for your web service.
$LoginClient = new SoapClient(“http://localhost/services/login.wsdl”, array(“trace”=>1));
// See the functions webservice is exposing
echo ‘<pre>’;
print_r($LoginClient->__getFunctions());
// Call the function
try
{
$arrResponse = $LoginClient->Logon(“abc”, “pqr”, “xyz”);
}
catch(SoapFault $exception)
{
echo $exception;
}
// Print response on screen
print_r($arrResponse);
// See what kind of xml request SoapClient is sending
$LoginClient->__getLastRequest();
// Check with what kind of xml response SoapServer is responding back
$LoginClient->getLastResponse();
Let’s see whether it helped or not? If you can provide wsdl then it would be easier to help.
#4 by toolsche on June 29, 2009 - 9:59 pm
Quote
Hi,
We are having issues consuming a PHP web-service with C#. The Problem is, that .NET can't correctly interprete the complex Array type Zend generated in the WSDL.
XSD:
—-
list of articles in basket
WSDL:
—–
C# reference.cs:
—————-
public PWDA_CouponCode checkCouponCode(string couponCode, string mandantID, string mandantCountry, string shippingCountry, PWDA_Articles articles)…
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:PWDAService")]
public partial class PWDA_ArticleArray : Array {
}
[System.Xml.Serialization.XmlIncludeAttribute(typeof(PWDA_ArticleArray))]
[System.SerializableAttribute()][System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.xmlsoap.org/soap/encoding/")]
public partial class Array {
private System.Xml.XmlElement[] anyField;
private string arrayTypeField;
private string offsetField;
private bool offsetFieldSpecified;
private string idField;
private string hrefField;
private System.Xml.XmlAttribute[] anyAttrField;
…
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:PWDAService")]
public partial class PWDA_Article {
private string amountField;
private string articleIDField;
…
Did anyone did solve this issue and can tell if the Zend WSDL generator can produce sth that .NET can interprete in order to generate sth like this:
public PWDA_CouponCode checkCouponCode(string couponCode, string mandantID, string mandantCountry, string shippingCountry, PWDA_Article[] articles)
#5 by Dharmavirsinh Jhala on June 30, 2009 - 3:27 am
Quote
Dear Friend,
I am sure I would be able to help you out.
Just provide me your current wsdl and I can send you the modified version of wsdl.
But yes then you have to use that version of wsdl instead of relying on auto-generation feature of Zend-framework.
#6 by Michael Krikorev on February 14, 2010 - 8:47 am
Quote
Dear Dharmavirsinh Jhala!
I've been tearing my hair of for weeks trying to build a simple PHP-client for a .NET Web Service. I've tried PHP:s Soap Extension witout any luck. Keep getting a SoapFault object error saying "Internal Server Error" (see http://exportalen.se/soapclient.php )
I know that the webservice is working with existing .NET clients, but I can't get it to work with a PHP-client (and I dont have access to the Web Service configuraton).
The Web Service use WS-Addressing 1.0 and SOAP 1.2 over a https URL: https://webservice.artdata.slu.se/WebService/ArtD…
I would be very grateful for any help to solve my problem! Someone said that I have to use xml-rpc (but I dont know how to use it together with the information in the WSDL-file).
MyPHP configuration is this:
http://exportalen.se/php.php
Many thanks in advance!
/Michael
Source code of my PHP-client (exportalen.se/soapclient.php) that generates an error:
$url = "https://webservice.artdata.slu.se/WebService/ArtDatabankenService.svc?wsdl";
$params = array('userName'=>'my_username', 'password'=>'my_password');
$client = new SoapClient($url, array("trace"=>1,"exceptions"=>0, "soap_version"=>SOAP_1_2));
//$client = new SoapClient(null, array('location' => $url, 'uri'=>'urn:WebServices.ArDataBanken.slu.se', 'trace'=>1, 'exceptions'=>0, 'soap_version'=>SOAP_1_2 ));
echo "";
$result = $client->Login($params);
print_r($result);
echo("
Request:
". htmlspecialchars($client->__getLastRequest()));
echo("
Request Headers:
". htmlspecialchars($client->__getLastRequestHeaders()));
echo("
Response Headers:
". htmlspecialchars($client->__getLastResponseHeaders()));
echo("
Response:
". htmlspecialchars($client->__getLastResponse()));
echo "
Functions and Types:
";
print_r($client->__getFunctions());
print_r($client->__getTypes());
echo "
";
#7 by Dharmavirsinh Jhala on February 16, 2010 - 4:01 am
Quote
Dear Michael,
I looked at the code and executed that. I am getting same error message as you are getting.
Though I have consumed webservice from PHP by both .NET or PHP or Apache Axis but never faced problem similar to this.
I will try again on this. But a question I am assuming that you don't have access to .NET code at all of "https://webservice.artdata.slu.se/WebService/ArtDatabankenService.svc" am I correct? To me it seems like there could be some config error from .NET side..as it seems like from what I looked at some forums.
Will get back to you in couple of days.. when I will get some more time to look at this.
Let me know if you get some solution on this.
#8 by Sergey on December 22, 2010 - 7:37 pm
Quote
I am now working on webservice. And i acannot finaly deside what to use either PHP or .net. I did not mit any problem with WSDL generation. Send Studio has abilty to create WSDLS visualy without even knowing the code. Although I corrected code there because I use difefrent php dfiles for difefrent Ports.
If this only the reason I would better use PHP. What about compatibility? Our service is going to be used by different devices. Web browsers, adroid, iphone, WP7, and so on… And is going to be very high loaded service. minimum 100 000 000 calls a month.
I have 2 main question. Is make any difference on .NET in terms of sufficensy and securilty? Will it make any difference when we start develop clients pn mobile devices?
I tended to use PHP.
What do you think?