我的程序需要从SOAP 1.1中的第三方Web服务进行查询,我使用VS 2013的服务引用从WSDL为它创建Web服务。
因为它是一个SOAP 1.1 Web服务,所以我在app.config中使用了basicHttpBinding,但是当我运行该程序时,它会抛出错误:
The content type application/soap+xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Header/><SOAP-ENV:Body><memberEnquiryResponse><errMsg>144859327293915198337416aFD&EQshadfq2w</errMsg><result>0</result><member><name>test2</name><phone>85297350833</phone><securityCode>9702</securityCode><memberID>151983374</memberID></member><points>10000</points><pointExpiry>201701312359</pointExpiry><accTransactionAmount>0.00</accTransactionAmount><lastTransactionDatetime>-</lastTransactionDatetime><coupons><coupon><id>159</id><type>2</type><netOff>20</netOff><offType>0</offType><itemCode>DIS:</itemCode><name>Sandwiches (receipt discount $)</name><expiry>20161113</expiry><description>Coupon Description (Chi)</description></coupon><coupon><id>158</id><type>1</type><netOff>10</netOff><offType>1</offType><name>Soup (item discount %)</name><expiry>20161113</expiry><description>Coupon Description (Chi)</description></coupon><coupon><id>160</id><type>2</ty'.
我发现服务器端响应的内容类型是 SOAP 1.2 application / soap + xml; charset = utf-8而不是 SOAP 1.1 text / xml;字符集= UTF-8
但是,它返回的名称空间是
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" />
所以我很确定它是一个SOAP 1.1 Web服务。 由于我无法从服务器端更改内容类型(它不受我控制),我能做的唯一方法是在收到响应后更改内容类型,或者将客户端设置为接受application / soap + xml; charset = utf-8作为SOAP 1.1内容类型。
有没有办法实现这个目标?谢谢!
迈克尔