0

I'm working on a asp.net webapplication, build in C#. I have to implement a third party web-service that is created using PHP. It is a very simple service containing only one function. I added the service reference using the wsdl, so far so good.

When I call the web-service function with the correct parameters it always returns null. I started troubleshooting with SoapUI. I captured the soap message from the application and pasted it in SoapUI, executed it and it returned the correct message. Using Fiddler I discovered something weird in the response from the web-service as shown in the raw output:

HTTP/1.1 200 OK
Date: Wed, 21 Nov 2012 15:24:31 GMT
Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/0.9.8o
X-Powered-By: PHP/5.2.13-pl1-gentoo
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=ddc342cfe7e56e77456fe31b758bf3de; path=/
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Content-Length: 812
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/xml; charset=utf-8

?????????KS?0???`r?~?<???   ?I
I?????0??+?.????kK.????[E?????[???????}??g4
?1J???~w?i??<?M?+w??[>]ziIc???.?
???yvi?"x?  F??d?Y?aR,4?X?
[UQ^F)?$`?
7??[?F"?$??h???S?a??4??Q?E??6Td,t6%Hg??w/)??????]??G*   ?l[??&6?0?$??>??????~?????:??6??W#?a????E?G?
s??Z????§o?_??c??\???-???)?????cc??w???/??f??}?)??r???????T?/???    m??K??8?    ?X?/F8?<???:?m???&f ?Z#[31?*?X,c?Z??0h"??aFb.?<??p??a???Q?B?r>????Z??5??6???????n\y?d?.??\??Hc]??
Z,?x??l???g?Q?*&???1?)??????^?????v??pQ???_y~??%??????*?
>???;??6?+?>???RQq?????a?(?Z????C?5???G??Ce??H?9??xYL|"??i?
e8?Vk???s???AK^?e~??
??(??Lt???r???vs????7??d?w???Jj-B????pt????c??MBi?s)Mo?.??^?aB3?x8&??:_K|???5???)[?M?Xc?j?zX?=G?i/??TO???g????5??c0??w???T??

The header is displayed correctly. The response is encoded and needs to be decoded. Both SoapUI and Fiddler are able to decode the response, but the proxy class can't and returns null.

How can I overcome this problem? Any help is greatly appreciated!

EDIT:

The way the service is called:

LisenceServiceFR.ServiceRegistration_PortTypeClient client = new LisenceServiceFR.ServiceRegistration_PortTypeClient();
LisenceServiceFR.aVehicleInfo info = client.getVehicleInfo("xxx", "xxx", licensePlate, "localhost");

Edit 2:

The response XML from Fiddler.

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://services.audaconfr.com/ServiceRegistration.wsdl">
    <SOAP-ENV:Body>
        <SOAP-ENV:getVehicleInfoResponse>
            <aVehicle>
                <ns1:errorCode>200</ns1:errorCode>
                <ns1:errorMessage>Success</ns1:errorMessage>
                <ns1:vehicleXml>
            &lt;vehicule&gt;
                &lt;carr&gt;MONOSPACE COMPACT&lt;/carr&gt;
                &lt;carr_cg&gt;CI&lt;/carr_cg&gt;
                &lt;co2&gt;152&lt;/co2&gt;
                <!-- etc -->
            &lt;/vehicule&gt;
        </ns1:vehicleXml>
            </aVehicle>
        </SOAP-ENV:getVehicleInfoResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
John Saunders
  • 160,644
  • 26
  • 247
  • 397
DirkV
  • 353
  • 1
  • 4
  • 16
  • Look at the header `Content-Encoding: gzip` - the payload is compressed. Can you show how you call the service? I guess the proxy should decompress it automatically. – Jan Nov 21 '12 at 16:06
  • 1
    _"When I call the web-service function with the correct parameters it always returns null."_ - I guess the payload is unzipped correctly, but the response is rendered invalid during deserialization. Can you show the decompressed XML as Fiddler shows it? – CodeCaster Nov 21 '12 at 16:09
  • Off topic, but you may want to correct the spelling of "Lisence" to "License" – StingyJack Nov 21 '12 at 16:59
  • Thanks for pointing out the typo... Do you also have a suggestion for the solution? ;) – DirkV Nov 21 '12 at 17:07
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Nov 21 '12 at 19:46
  • This question shows how to gzip/ungzip SOAP streams: http://stackoverflow.com/questions/370156/compressing-web-service-request – Thymine Nov 21 '12 at 20:39

1 Answers1

0

I ended up using HttpWebRequest to call the webservice:

System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.InnerXml = xml;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(endPoint);
req.Timeout = 100000000;

if (proxy != null)
    req.Proxy = new WebProxy(proxy, true);

req.Headers.Add("SOAPAction", "");
req.ContentType = "application/soap+xml;charset=\"utf-8\"";
req.Accept = "application/x-www-form-urlencoded"; 
req.Method = "POST";
Stream stm = req.GetRequestStream();
doc.Save(stm);
stm.Close();
WebResponse resp = req.GetResponse();
stm = resp.GetResponseStream();
StreamReader r = new StreamReader(stm);
string responseData = r.ReadToEnd();

XDocument response = XDocument.Parse(responseData);

/* extract data from response */

It was not the solution I was looking for, but is works like a charm.

DirkV
  • 353
  • 1
  • 4
  • 16