Skip to main content
 首页 » 编程设计

c#之使用 Web 服务时类型不兼容

2024年01月02日34telwanggs

我必须使用一个返回字符串作为结果的网络服务,它也有一些字符串参数,所以我所做的所有事情都是这样的: 1- 我已将该服务引用添加到我的项目中。 2- 我创建了该服务类的一个实例 3- 我在类实例中调用了一个 desire 函数

这是我的代码:

     MyServiceNS.PscoWSDLPortTypeClient mys= new MyServiceNS.PscoWSDLPortTypeClient(); 
     string res; 
     res =mys.srvReq("11320000", "21310000", "13901009", "1", "3"); 

但问题是当我调用 mys.srvReq 时出现如下错误:

The content type text/xml; charset=ISO-8859-1 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 572 bytes of the response were: ?xml version="1.0" encoding="ISO-8859-1"?SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-

请您参考如下方法:

据我了解,问题在于 WFC 不支持 ISO-88859-1 编码。 默认的 WFC 编码器只支持 utf-8 和 utf-16 编码。

您可以根据 msdn 创建合适的自定义编码器: http://msdn.microsoft.com/en-us/library/ms751486.aspx

和/或修改这个有用的例子 http://eclectrics.com/software/2009/09/getting-the-current-weather-conditions/