0

我正在开发一个用 C# 构建的 asp.net web 应用程序。我必须实现使用 PHP 创建的第三方 Web 服务。这是一个非常简单的服务,只包含一个功能。我使用 wsdl 添加了服务引用,到目前为止一切顺利。

当我使用正确的参数调用 Web 服务函数时,它总是返回 null。我开始使用 SoapUI 进行故障排除。我从应用程序中捕获了肥皂消息并将其粘贴到 SoapUI 中,执行它并返回正确的消息。使用 Fiddler,我在来自 web 服务的响应中发现了一些奇怪的东西,如原始输出所示:

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??

标题显示正确。响应已编码,需要解码。SoapUI 和 Fiddler 都能够解码响应,但代理类不能并返回 null。

我该如何克服这个问题?任何帮助是极大的赞赏!

编辑:

服务调用方式:

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

编辑2:

来自 Fiddler 的响应 XML。

<?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>
4

1 回答 1

0

我最终使用 HttpWebRequest 来调用网络服务:

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 */

这不是我正在寻找的解决方案,但它就像一个魅力。

于 2012-11-27T15:16:44.643 回答