响应消息的内容类型 text/xml; charset=ISO-8859-1 与绑定(text/xml; charset=utf-8)的内容类型不匹配。如果使用
用c#测试个合作伙伴公司的webservice(php编写的),测试代码:
protected void Page_Load(object sender, EventArgs e)
{
bzezt.getmesxmlPortTypeClient ptc = new bzezt.getmesxmlPortTypeClient();
string rtn = ptc.getmesxml("test", MD5Encoding("888888"));
}
public static string MD5Encoding(string rawPass)
{
// 创建MD5类的默认实例:MD5CryptoServiceProvider
MD5 md5 = MD5.Create();
byte[] bs = Encoding.UTF8.GetBytes(rawPass);
byte[] hs = md5.ComputeHash(bs);
StringBuilder sb = new StringBuilder();
foreach (byte b in hs)
{
// 以十六进制格式格式化
sb.Append(b.ToString("x2"));
}
return sb.ToString();
}
报如下错误:
“/WebSite3”应用程序中的服务器错误。
响应消息的内容类型 text/xml; charset=ISO-8859-1 与绑定(text/xml; charset=utf-8)的内容类型不匹配。如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。响应的前 1024 个字节为:“<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getmesxmlResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"><return xsi:type="xsd:string"><?xml version="1.0" encoding="utf-8"?>
<Request>
<scenery>
<scn_state>1</scn_state>
<sid>955</sid>
<uid>2007359</uid>
<name>抚顺皇家海洋乐园</name>
<provineid>18</provineid>
<cityid>244</cityid>
<areaid>-22</areaid>
<address>辽宁省抚顺市高湾开发区高阳路3号</address>
<info>%3Cp%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B+%E7%9A%87%E5%AE%B6%E6%B5%B7%E6%B4%8B%E4%B9%90%E5%9B%AD%EF%BC%8C%E7%9B%AE”。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ServiceModel.ProtocolException: 响应消息的内容类型 text/xml; charset=ISO-8859-1 与绑定(text/xml; charset=utf-8)的内容类型不匹配。如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。响应的前 1024 个字节为:“<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getmesxmlResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"><return xsi:type="xsd:string"><?xml version="1.0" encoding="utf-8"?>
<Request>
<scenery>
<scn_state>1</scn_state>
<sid>955</sid>
<uid>2007359</uid>
<name>抚顺皇家海洋乐园</name>
<provineid>18</provineid>
<cityid>244</cityid>
<areaid>-22</areaid>
<address>辽宁省抚顺市高湾开发区高阳路3号</address>
<info>%3Cp%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B+%E7%9A%87%E5%AE%B6%E6%B5%B7%E6%B4%8B%E4%B9%90%E5%9B%AD%EF%BC%8C%E7%9B%AE”。
源错误:
行 89: [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
行 90: bzezt.getmesxmlResponse bzezt.getmesxmlPortType.getmesxml(bzezt.getmesxmlRequest request) {
行 91: return base.Channel.getmesxml(request);
行 92: }
行 93:
源文件: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\website3\a307838f\3c9d09e4\App_WebReferences.ns_ixokz.0.cs 行: 91
堆栈跟踪:
[ProtocolException: 响应消息的内容类型 text/xml; charset=ISO-8859-1 与绑定(text/xml; charset=utf-8)的内容类型不匹配。如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。响应的前 1024 个字节为:“<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getmesxmlResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"><return xsi:type="xsd:string"><?xml version="1.0" encoding="utf-8"?>
<Request>
<scenery>
<scn_state>1</scn_state>
<sid>955</sid>
<uid>2007359</uid>
<name>抚顺皇家海洋乐园</name>
<provineid>18</provineid>
<cityid>244</cityid>
<areaid>-22</areaid>
<address>辽宁省抚顺市高湾开发区高阳路3号</address>
<info>%3Cp%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B+%E7%9A%87%E5%AE%B6%E6%B5%B7%E6%B4%8B%E4%B9%90%E5%9B%AD%EF%BC%8C%E7%9B%AE”。]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9442991
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
bzezt.getmesxmlPortType.getmesxml(getmesxmlRequest request) +0
bzezt.getmesxmlPortTypeClient.bzezt.getmesxmlPortType.getmesxml(getmesxmlRequest request) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\website3\a307838f\3c9d09e4\App_WebReferences.ns_ixokz.0.cs:91
bzezt.getmesxmlPortTypeClient.getmesxml(String uname, String pwd) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\website3\a307838f\3c9d09e4\App_WebReferences.ns_ixokz.0.cs:98
_Default.Page_Load(Object sender, EventArgs e) in c:\Users\Administrator\Documents\Visual Studio 2010\WebSites\WebSite3\Default.aspx.cs:16
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
版本信息: Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.1022
搞了一上午了,还没解决。尴尬!求高手