简体   繁体   English

响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8)

[英]The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)

I trying to consume a WCF web service using stand alone application. 我试图使用独立应用程序使用WCF Web服务。 I am able to view this service using Internet Explorer also able to view in Visual studio service references. 我可以使用Internet Explorer查看此服务,也可以在Visual Studio服务参考中查看。

This is the error I am getting 这是我得到的错误

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).

How do I change this to use the correct content type? 如何更改它以使用正确的内容类型?

Here is my config file 这是我的配置文件

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

here is the stack 这是堆栈

{System.ServiceModel.ProtocolException: The content type application/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: '<Exception>org.apache.axis2.AxisFault: The endpoint reference (EPR) for the Operation not found is /janus/services/G2WebService and the WSA Action = null&#xd;
    at org.apache.axis2.engine.DispatchPhase.checkPostConditions(DispatchPhase.java:89)&#xd;
    at org.apache.axis2.engine.Phase.invoke(Phase.java:333)&#xd;
    at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:264)&#xd;
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:163)&#xd;
    at org.apache.axis2.transport.http.util.RESTUtil.invokeAxisEngine(RESTUtil.java:136)&#xd;
    at org.apache.axis2.transport.http.util.RESTUtil.processURLRequest(RESTUtil.java:130)&#xd;
    at org.apache.axis2.transport.http.AxisServlet$RestRequestProcessor.processURLRequest(AxisServlet.java:829)&#xd;
    at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:255)&#xd;
    at com.rm.janus.webservice.GroupCallServlet.doGet(GroupCallServlet.java:33)&#xd;
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)&#xd;
    at javax.servlet.http.HttpSer'. ---> System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at InetgrisG2TestApp.G2ServiceReference.G2WebServicePortType.getStudentData(getStudentDataRequest request)
   at InetgrisG2TestApp.G2ServiceReference.G2WebServicePortTypeClient.G2TestApp.G2ServiceReference.G2WebServicePortType.getStudentData(getStudentDataRequest request) in c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\InetgrisG2TestApp\Service References\G2ServiceReference\Reference.cs:line 2981
   at InetgrisG2TestApp.G2ServiceReference.G2WebServicePortTypeClient.getStudentData(ServiceRequest serviceReq) in c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\G2TestApp\Service References\G2ServiceReference\Reference.cs:line 2987
   at InetgrisG2TestApp.Program.Main(String[] args) in c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\G2TestApp\Program.cs:line 57}

It's possible that your WCF service is returning HTML. 您的WCF服务有可能返回HTML。 In this case, you'll want to set up a binding on the service side to return XML instead. 在这种情况下,您将需要在服务端设置一个绑定以代替返回XML。 However, this is unlikely: if it is the case, let me know and I'll make an edit with more details. 但是,这不太可能:如果这种情况,请告诉我,我将进行更详细的编辑。

The more likely reason is that your service is throwing an error, which is returning an HTML error page. 更有可能的原因是您的服务抛出了错误,该错误返回了HTML错误页面。 You can take a look at this blog post if you want details. 如果需要详细信息,可以查看此博客文章

tl;dr: There are a few possible configurations for error pages. tl; dr:错误页面有几种可能的配置。 If you're hosting on IIS, you'll want to remove the <httpErrors> section from the WCF service's web.config file. 如果您在IIS上托管,则需要从WCF服务的web.config文件中删除<httpErrors>部分。 If not, please provide details of your service hosting scenario and I can come up with an edit to match them. 如果没有,请提供您的服务托管方案的详细信息,我可以进行修改以使其匹配。

EDIT: 编辑:

Having seen your edit, you can see the full error being returned. 看完您的编辑后,您可以看到返回的完整错误。 Apache can't tell which service you want to call, and is throwing an error for that reason. Apache无法告诉您要调用哪个服务,并且由于这个原因抛出了错误。 The service will work fine once you have the correct endpoint - you're pointed at the wrong location. 一旦您拥有正确的端点,该服务将正常运行-您被指向错误的位置。 I unfortunately can't tell from the information available what the right location is, but either your action (currently null !) or the URL is incorrect. 不幸的是,我无法从可用信息中得知正确的位置是什么,但是您的操作(当前为null !)或URL不正确。

When I ran into this error, I spent hours trying to find a solution. 当我遇到此错误时,我花费了数小时试图找到解决方案。

My issue was that when I went to save the file I had accidentally hit the key stroke "G" in the web.config. 我的问题是,当我去保存文件时,无意中击中了web.config中的按键“ G”。 I had a straggler Character just sittings outside, so the web.config did not know how to interpret the improperly formatted data. 我只有一个散乱的角色坐在外面,所以web.config不知道如何解释格式不正确的数据。

Hope this helps. 希望这可以帮助。

Just in case... 以防万一...
If you are using SoapUI Mock Service (as the Server), calling it from a C# WCF : 如果您正在使用SoapUI模拟服务 (作为服务器),请从C#WCF调用它:

WCF --> SoapUI MockService

And in this case you are getting the same error: 在这种情况下,您将得到相同的错误:

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).

Edit your Mock Response at SoapUI and add a Header to it: 在SoapUI上编辑模拟响应,然后向其中添加标题: 在此处输入图片说明

In my scenario, this fix the problem. 在我的情况下,这解决了问题。

We use the Url Rewrite extension for IIS for redirecting all HTTP requests to HTTPS. 我们使用IIS的Url Rewrite扩展名将所有HTTP请求重定向到HTTPS。 When trying to call a service not using transport security on an http://... address, this is the error that appeared. 尝试在不使用http:// ...地址上的传输安全性的服务上调用时,这是出现的错误。

So it might be worth checking if you can hit both the http and https addresses of the service via a browser and that it doesn't auto forward you with a 303 status code. 因此,值得一提的是,您是否可以通过浏览器同时访问服务的http和https地址,并且不会通过303状态代码自动转发给您。

In WCF serive project this issue may be due to Reference of System.Web.Mvc.dll 's different version or may be any other DLL's different version issue. 在WCF服务项目中,此问题可能是由于参考System.Web.Mvc.dll的不同版本引起的,或者可能是任何其他DLL的不同版本引起的。 So this may be compatibility issue of DLL's different version 所以这可能是DLL不同版本的兼容性问题

When I use 当我使用

System.Web.Mvc.dll version 5.2.2.0 -> it thorows the Error The content type text/html; System.Web.Mvc.dll版本 5.2.2.0->引发错误 charset=utf-8 of the response message 响应消息的charset = utf-8

but when I use 但是当我使用

System.Web.Mvc.dll version 4.0.0.0 or lower -> That's works fine in my project and not have an Error. System.Web.Mvc.dll版本4.0.0.0或更低版本 ->在我的项目中工作正常 ,没有错误。

I don't know the reason of this different version of DLL's issue but when I change the DLL's verison which is compatible with your WCF Project than it works fine. 我不知道此DLL版本不同的原因,但是当我更改与您的WCF项目兼容的DLL版本时,它会正常工作。

This Error even generate when you add reference of other Project in your WCF Project and this reference project has different version of System.Web.Mvc DLL or could be any other DLL. 当您在WCF项目中添加其他项目的引用并且此引用项目具有不同版本的System.Web.Mvc DLL或可能是任何其他DLL时,甚至会生成此错误。

In my case it was simply an error in the web.config. 就我而言,这只是web.config中的错误。

I had: 我有:

<endpoint address="http://localhost/WebService/WebOnlineService.asmx" 

It should have been: 应该是:

<endpoint address="http://localhost:10593/WebService/WebOnlineService.asmx"

The port number (:10593) was missing from the address. 地址中缺少端口号(:10593)。

This could be an error in the web.config file. 这可能是web.config文件中的错误。

Open up your URL in your browser, example: 在浏览器中打开您的URL,例如:

http://localhost:61277/Email.svc

Check if you have a 500 Error. 检查是否有500错误。

HTTP Error 500.19 - Internal Server Error

Look for the error in these sections: 在以下部分中查找错误:

Config Error 配置错误

Config File 配置文件

Try browse the WCF in IIS see if it's alive and works normally, 尝试在IIS中浏览WCF,看看它是否还可以正常运行,

In my case it's because the physical path of the WCF is misdirected. 就我而言,这是因为WCF的物理路径错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 响应消息的内容类型 application/xml;charset=utf-8 与绑定的内容类型(text/xml; charset=utf-8)不匹配,WCF - The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8), WCF 内容类型 text/xml; 响应消息的 charset=&quot;utf-8&quot; 与绑定的内容类型不匹配 (text/xml; charset=utf-8) - The content type text/xml; charset=“utf-8” of the response message does not match the content type of the binding (text/xml; charset=utf-8) 内容类型text / html; charset =响应消息的UTF-8与绑定的内容类型不匹配(text / xml; charset = utf-8) - 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) 响应消息的内容类型文本/纯文本与绑定的内容类型不匹配(文本/ xml; charset = utf-8) - The content type text/plain of the response message does not match the content type of the binding (text/xml; charset=utf-8) wcf +响应消息的内容类型text / html与绑定的内容类型不匹配(application / soap + xml; charset = utf-8) - wcf + The content type text/html of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8) HTTP 415 无法处理消息,因为内容类型为“application/json; charset=utf-8&#39; 不是预期的类型 &#39;text/xml; 字符集=utf-8&#39; - HTTP 415 Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8' 无法处理消息,因为内容类型为 &#39;application/json; charset=utf-8&#39; 不是预期的类型 &#39;text/xml; 字符集=utf-8&#39; - Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8' WCF http绑定错误:内容类型text / html与绑定的内容类型不匹配(text / xml; charset = utf-8) - WCF http binding error: The content type text/html does not match the content type of the binding (text/xml; charset=utf-8) WCF 服务客户端:内容类型text/html; 响应消息的 charset=utf-8 与绑定的内容类型不匹配 - WCF Service Client: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding 无法处理该消息,因为内容类型“ application / xml”不是预期的类型“ application / soap + xml”; 字符集= utf-8&#39; - Cannot process the message because the content type 'application / xml' was not the expected type 'application / soap + xml; charset = utf-8 '
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM