Consuming PHP-webservice with C#

  • Thread starter Thread starter Thomas Mueller
  • Start date Start date
T

Thomas Mueller

Hi,
I'm currently working on C# code consuming a PHP-webservice
(soapserver-class of PHP5). A PHP test-client worked fine and achieved
the requested data from the service's server.

Using the wsdl-file of the webservice, wsdl.exe generated a C#-proxy
class errorlessly. I then tried to instantiate the proxy class to access
the service:

waClient.waService was = new waClient.waService();
waClient.tCourseDescription cd = was.getCourseByKey("12345");

It compiles without errors or warnings but after calling the
getCourseByKey-methode, it throughs an exception, reporting that the
given type is unknown:

(Name=map, Namespace=Namespace='http://xml.apache.org/xml-soap', at
<courseDescription xmlns=''>

Using a traffic sniffer, I found out, that the php webservice-server
sends the following response to the C# client instance:

###
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="urn:course"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns2="http://xml.apache.org/xml-soap"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>

<ns1:getCourseByKeyResponse>
<courseDescription xsi:type="ns2:map">
<item>
<key xsi:type="xsd:string">language</key>
<value xsi:type="xsd:string">de</value>
</item>
[..]
</courseDescription>
</ns1:getCourseByKeyResponse>

</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
###

C# seems not to be able to deserialize the map-element of the apache.org
namespace. What can I do get the respons data?

Is it possible to get the plain xml-response in C# (to deserialize it
manually to the target object)? How?

Thanks a lot for any hint!
Thomas
 
Thomas said:
I'm currently working on C# code consuming a PHP-webservice
(soapserver-class of PHP5). A PHP test-client worked fine and achieved
the requested data from the service's server.

Using the wsdl-file of the webservice, wsdl.exe generated a C#-proxy
class errorlessly. I then tried to instantiate the proxy class to access
the service:

waClient.waService was = new waClient.waService();
waClient.tCourseDescription cd = was.getCourseByKey("12345");

It compiles without errors or warnings but after calling the
getCourseByKey-methode, it throughs an exception, reporting that the
given type is unknown:

(Name=map, Namespace=Namespace='http://xml.apache.org/xml-soap', at
<courseDescription xmlns=''>

Using a traffic sniffer, I found out, that the php webservice-server
sends the following response to the C# client instance:

###
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="urn:course"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns2="http://xml.apache.org/xml-soap"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>

<ns1:getCourseByKeyResponse>
<courseDescription xsi:type="ns2:map">
<item>
<key xsi:type="xsd:string">language</key>
<value xsi:type="xsd:string">de</value>
</item>
[..]
</courseDescription>
</ns1:getCourseByKeyResponse>

</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
###

C# seems not to be able to deserialize the map-element of the apache.org
namespace. What can I do get the respons data?

Is it possible to get the plain xml-response in C# (to deserialize it
manually to the target object)? How?

SOAP and WSDL allows you to make technology independent
web services - it does not force you to do so.

Using other standards like WS-I Basic Profile is necessary
to enforce portability.

My guess is that the PHP service is doing something PHP'ish and
that is why .NET can not handle it.

If changing the PHP is an option we could try and loop at the
PHP code, the WSDL and the SOAP to come up with a solution.

If changing the PHP is not an option, then you could fallback to
(Http)WebRequest and write and read the XML manually.

Sniff what the PHP client send and receive and code from that.

I think I have some C# code parsing SOAP XML somewhere if you
are interested.

Arne
 
Back
Top