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

我尝试使用独立应用程序使用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). 

如何更改此选项以使用正确的内容类型?

这是我的配置文件

                       

这是堆栈

 {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: '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} 

您的WCF服务可能正在返回HTML。 在这种情况下,您需要在服务端设置绑定以返回XML。 但是,这不太可能:如果这种情况,请告诉我,我将进行更多细节的编辑。

更可能的原因是您的服务引发了错误,即返回HTML错误页面。 如果您需要详细信息,可以查看此博客文章 。

tl; dr:错误页面有一些可能的配置。 如果您在IIS上托管,则需要从WCF服务的web.config文件中删除部分。 如果没有,请提供您的服务托管方案的详细信息,我可以进行编辑以匹配它们。

编辑:

看过您的编辑后,您可以看到返回的完整错误。 Apache无法分辨您要调用哪个服务,并因此出现错误。 一旦拥有正确的端点,该服务将正常工作 – 您指向错误的位置。 遗憾的是,我无法从可用信息中判断出正确的位置,但您的操作(当前为null !)或URL不正确。

当我遇到这个错误时,我花了好几个小时试图找到解决方案。

我的问题是,当我去保存文件时,我不小心碰到了web.config中的键击“G”。 我有一个懒散的角色只是坐在外面,所以web.config不知道如何解释格式不正确的数据。

希望这可以帮助。

以防万一…
如果您正在使用SoapUI Mock Service (作为服务器),请从C#WCF调用它:

 WCF --> SoapUI MockService 

在这种情况下,您得到相同的错误:

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

在SoapUI编辑模拟响应并为其添加标题: 在此处输入图像描述

在我的方案中,这解决了问题。

我们使用IIS的Url Rewrite扩展来将所有HTTP请求重定向到HTTPS。 当尝试在http:// …地址上调用不使用传输安全性的服务时,这就是出现的错误。

因此,如果您可以通过浏览器同时访问服务的http和https地址,并且它不会使用303状态代码自动转发您,则可能值得检查。

在WCF服务项目中,此问题可能是由于System.Web.Mvc.dll的不同版本的引用,或者可能是任何其他DLL的不同版本问题。 所以这可能是DLL的不同版本的兼容性问题

我用的时候

System.Web.Mvc.dll版本5.2.2.0 – >它引发错误内容类型text / html; 响应消息的charset = utf-8

但是当我用的时候

System.Web.Mvc.dll版本4.0.0.0或更低版本 – >这在我的项目中工作正常 ,没有错误。

我不知道这个不同版本的DLL问题的原因,但是当我更改与你的WCF项目兼容的DLL的verison比它工作正常。

当您在WCF项目中添加其他Project的引用时,甚至会生成此错误,并且此引用项目具有不同版本的System.Web.Mvc DLL或可能是任何其他DLL。

就我而言,它只是web.config中的一个错误。

我有:

  

应该是:

  

地址中缺少端口号(:10593)。

这可能是web.config文件中的错误。

在浏览器中打开您的URL,例如:

 http://localhost:61277/Email.svc 

检查是否有500错误。

 HTTP Error 500.19 - Internal Server Error 

在这些部分中查找错误:

配置错误

配置文件

尝试浏览IIS中的WCF,看看它是否还活着并正常工作,

在我的情况下,这是因为WCF的物理路径是错误的。