我在我的本地IIS服务器上运行了一个WCF服务.我已将其添加为C#Website Project的服务引用,并且它会添加正常并自动生成代理类.
但是,当我尝试调用任何服务合同时,我收到以下错误:
描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息: System.ServiceModel.ProtocolException:内容类型text/html; 所述响应消息不匹配的结合(;字符集= UTF-8应用/肥皂+ XML)的内容类型的字符集= UTF-8.如果使用自定义编码器,请确保正确实现IsContentTypeSupported方法.响应的前1024个字节是:'function bredir(d,u,r,v,c){var w,h,wd,hd,bi; var b = false; var p = false; var s = [[ 300250,假],[250250,假],[240400,假],[336280,假],[180150,假],[468,60,假],[234,60,假],[88,31,假],[120,90,假],[120,60,假],[120240,假],[125125,假],[728,90,假],[160600,假],[120600,假] [300600,假],[300125,假],[530300,假],[190200,假],[470250,假],[720300,真],[500350,真],[550480,真]]; if(typeof(window.innerHeight)=='number'){h = window.innerHeight; w = window.innerWidth;} else if(typeof(document.body.offsetHeight)=='number'){h = document. body.offsetHeight; w = document.body.offsetWidth;} for(var i = 0; i
我还有一个控制台应用程序,它也与WCF服务通信,控制台应用程序能够调用方法,而不会出现此错误.
以下是我的配置文件的摘录.
WCF服务Web.Config:
<system.serviceModel>
<services>
<service name="ScraperService" behaviorConfiguration="ScraperServiceBehavior">
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IScraperService"
contract="IScraperService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://example.com" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IScraperService"
bypassProxyOnLocal="false" transactionFlow="false" …Run Code Online (Sandbox Code Playgroud) 我尝试使用独立应用程序使用WCF Web服务.我能够使用Internet Explorer查看此服务,也可以在Visual Studio服务引用中查看.
这是我得到的错误
The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8).
Run Code Online (Sandbox Code Playgroud)
如何更改此选项以使用正确的内容类型?
这是我的配置文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="G2WebServiceSoap11Binding" />
</basicHttpBinding>
<customBinding>
<binding name="G2WebServiceSoap12Binding">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://XXX.XX.XX.XX:XX/janus/services/G2WebService.G2WebServiceHttpSoap11Endpoint/"
binding="basicHttpBinding" bindingConfiguration="G2WebServiceSoap11Binding"
contract="G2ServiceReference.G2WebServicePortType"
name="G2WebServiceHttpSoap11Endpoint" />
<endpoint address="http://XXX.XX.XX.XX:XX/janus/services/G2WebService.G2WebServiceHttpSoap12Endpoint/"
binding="customBinding" bindingConfiguration="G2WebServiceSoap12Binding"
contract="G2ServiceReference.G2WebServicePortType"
name="G2WebServiceHttpSoap12Endpoint" />
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
这是堆栈
{System.ServiceModel.ProtocolException: The content type application/xml;charset=utf-8 of …Run Code Online (Sandbox Code Playgroud) 我正在尝试开发一个Web应用程序,使用WCF向Web服务提交一个简单的登录请求,但我不断收到"内容类型文本/响应消息的明文不匹配"错误,即使Web服务似乎正在返回有效的XML.
我已经回顾了有关此错误的数十篇类似的SO帖子,并排除了更常见的可能性:
还有什么可能导致我的错误,为什么这不被认为是有效的XML?
我正在为我的应用程序使用.Net 4.0和Visual Studio 2010,它在单独的服务器上与Java/Tomcat Web服务进行通信.
以下是我的登录代码的相关摘录:
AuthenticationServiceClient client = new AuthenticationServiceClient(strPortName, strURL);
client.Open();
UserCredentials credentials = new UserCredentials();
credentials.userName = TestUsername;
credentials.password = TestPassword;
LoginResponse response = client.login(credentials); // Using WCF.
Run Code Online (Sandbox Code Playgroud)
这是绑定在我的Web.Config中的样子:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="AuthenticationServiceSoapBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://mywebserviceurl"
binding="basicHttpBinding" bindingConfiguration="AuthenticationServiceSoapBinding"
contract="MyNamespace.AuthenticationService" name="AuthenticationServiceImplPort" />
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
这是我的错误信息:
在"WebServiceURL"上测试与Web服务的连接时出错:System.ServiceModel.ProtocolException:响应消息的内容类型text/plain与绑定的内容类型(text/xml; charset = utf-8)不匹配.如果使用自定义编码器,请确保正确实现IsContentTypeSupported方法.响应的前788个字节是:'
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<loginReponse xmlns="urn:xxxx">
<authKey>xxxx</authKey>
<authMetadata>
<IPaddress>https://MyWebApplicationURL</IPaddress>
<loginTimestamp>xxxx</loginTimestamp><levelOfAssurance>
<AuthMechanism>xxxx</AuthMechanism>
<VettingAssertion>xxxx</VettingAssertion>
</levelOfAssurance> …Run Code Online (Sandbox Code Playgroud)