C# 响应消息的内容类型 application/xml;charset=utf-8 与绑定的内容类型不匹配 (text/xml; charset=utf-8)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15481092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
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)
提问by level_zebra
I trying to consume a WCF web service using stand alone application. I am able to view this service using Internet Explorer also able to view in Visual studio service references.
我尝试使用独立应用程序使用 WCF Web 服务。我可以使用 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
at org.apache.axis2.engine.DispatchPhase.checkPostConditions(DispatchPhase.java:89)
at org.apache.axis2.engine.Phase.invoke(Phase.java:333)
at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:264)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:163)
at org.apache.axis2.transport.http.util.RESTUtil.invokeAxisEngine(RESTUtil.java:136)
at org.apache.axis2.transport.http.util.RESTUtil.processURLRequest(RESTUtil.java:130)
at org.apache.axis2.transport.http.AxisServlet$RestRequestProcessor.processURLRequest(AxisServlet.java:829)
at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:255)
at com.rm.janus.webservice.GroupCallServlet.doGet(GroupCallServlet.java:33)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
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}
采纳答案by Steve Westbrook
It's possible that your WCF service is returning HTML. In this case, you'll want to set up a binding on the service side to return XML instead. However, this is unlikely: if it isthe case, let me know and I'll make an edit with more details.
您的 WCF 服务可能正在返回 HTML。在这种情况下,您需要在服务端设置一个绑定来返回 XML。但是,这不太可能:如果是这种情况,请告诉我,我将进行更详细的编辑。
The more likely reason is that your service is throwing an error, which is returning an HTML error page. You can take a look at this blog postif you want details.
更可能的原因是您的服务抛出错误,即返回 HTML 错误页面。如果您需要详细信息,可以查看此博客文章。
tl;dr:There are a few possible configurations for error pages. If you're hosting on IIS, you'll want to remove the <httpErrors>
section from the WCF service's web.config
file. If not, please provide details of your service hosting scenario and I can come up with an edit to match them.
tl;dr:错误页面有几种可能的配置。如果您在 IIS 上托管,您需要<httpErrors>
从 WCF 服务的web.config
文件中删除该部分。如果没有,请提供您的服务托管方案的详细信息,我可以进行编辑以匹配它们。
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. 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 rightlocation is, but either your action (currently null
!) or the URL is incorrect.
看到您的编辑后,您可以看到返回的完整错误。Apache 无法判断您要调用哪个服务,因此会引发错误。一旦您拥有正确的端点,该服务就会正常工作 - 您指向了错误的位置。我遗憾的是不能从现有的信息是什么告诉右位置,但无论你的行动(目前null
!),或者URL不正确。
回答by Demodave
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. I had a straggler Character just sittings outside, so the web.config did not know how to interpret the improperly formatted data.
我的问题是,当我去保存文件时,我不小心在 web.config 中按下了击键“G”。我有一个落后的角色坐在外面,所以 web.config 不知道如何解释格式不正确的数据。
Hope this helps.
希望这可以帮助。
回答by Tikall
We use the Url Rewrite extension for IIS for redirecting all HTTP requests to HTTPS. When trying to call a service not using transport security on an http://... address, this is the error that appeared.
我们使用 IIS 的 Url Rewrite 扩展将所有 HTTP 请求重定向到 HTTPS。在尝试调用不使用 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 状态代码。
回答by Tikall
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)。
回答by live-love
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
配置文件
回答by Ualter Jr.
Just in case...
If you are using SoapUI Mock Service(as the Server), calling it from a C# WCF:
以防万一...
如果您使用SoapUI Mock Service(作为服务器),请从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 上编辑您的 Mock Response 并向其添加标题:
In my scenario, this fix the problem.
在我的场景中,这解决了问题。
回答by Dilip0165
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. So this may be compatibility issue of DLL's different version
在 WCF 服务项目中,此问题可能是由于 System.Web.Mvc.dll 的不同版本的引用或可能是任何其他 DLL 的不同版本问题。所以这可能是DLL不同版本的兼容性问题
When I use
当我使用
System.Web.Mvc.dll version 5.2.2.0-> it thorows the ErrorThe content type text/html; charset=utf-8 of the response message
System.Web.Mvc.dll 版本 5.2.2.0-> 它抛出错误内容类型 text/html; 响应消息的字符集=utf-8
but when I use
但是当我使用
System.Web.Mvc.dll version 4.0.0.0 or lower-> That's works finein 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 时,甚至会生成此错误。
回答by yu yang Jian
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 的物理路径被误导了。