Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 内容类型为application/xml;响应消息的charset=utf-8与绑定的内容类型不匹配(text/xml;charset=utf-8)_C#_Wcf_Wcf Binding - Fatal编程技术网

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

C# 内容类型为application/xml;响应消息的charset=utf-8与绑定的内容类型不匹配(text/xml;charset=utf-8),c#,wcf,wcf-binding,C#,Wcf,Wcf Binding,我试图使用独立应用程序使用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). 如何更改此设置以使用正确的内容类型 这是我的配

我试图使用独立应用程序使用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).
如何更改此设置以使用正确的内容类型

这是我的配置文件

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

这是书堆

{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}
{System.ServiceModel.ProtocolException:响应消息的内容类型application/xml;charset=utf-8与绑定的内容类型(text/xml;charset=utf-8)不匹配。如果使用自定义编码器,请确保正确实现IsContentTypeSupported方法。
响应的前1024个字节是:“org.apache.axis2.AxisFault:找不到操作的端点引用(EPR)是/janus/services/G2WebService,WSA Action=null
;
在org.apache.axis2.engine.DispatchPhase.checkPostConditions(DispatchPhase.java:89)和#xd;
在org.apache.axis2.engine.Phase.invoke(Phase.java:333)和xd;
在org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:264)和#xd;
在org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:163)和#xd;
在org.apache.axis2.transport.http.util.RESTUtil.invokeAxisEngine(RESTUtil.java:136)和#xd;
在org.apache.axis2.transport.http.util.RESTUtil.processURLRequest(RESTUtil.java:130)和#xd;
在org.apache.axis2.transport.http.AxisServlet$RestRequestProcessor.processURLRequest(AxisServlet.java:829)和#xd;
在org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:255)和#xd;
在com.rm.janus.webservice.GroupCallServlet.doGet(GroupCallServlet.java:33)和xd;
在javax.servlet.http.HttpServlet.service(HttpServlet.java:690)和xd;
在javax.servlet.http.HttpSer'.-->System.Net.WebException:远程服务器返回错误:(500)内部服务器错误。
在System.Net.HttpWebRequest.GetResponse()中
位于System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度超时)
---内部异常堆栈跟踪的结束---
服务器堆栈跟踪:
位于System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest请求、HttpWebResponse响应、HttpChannelFactory`1工厂、WebException响应Exception、ChannelBinding ChannelBinding)
位于System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度超时)
位于System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan超时)
位于System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan超时)
在System.ServiceModel.Channels.ServiceChannel.Call(字符串操作、布尔单向、ProxyOperationRuntime操作、对象[]输入、对象[]输出、时间跨度超时)
位于System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage方法调用,ProxyOperationRuntime操作)
位于System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)
在[0]处重试异常:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)
at System.Runtime.Remoting.proxy.RealProxy.PrivateInvoke(MessageData&msgData,Int32类型)
在InetgrisG2TestApp.G2ServiceReference.G2WebServicePortType.getStudentData(getStudentDataRequest请求)中
在c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\InetgrisG2TestApp\Service References\G2ServiceReference.G2WebServicePortType.getStudentData(getStudentDataRequest请求)中的InetgrisG2TestApp.G2ServiceReference.G2WebServicePortTypeClient.G2TestApp.G2TestApp.G2ServiceReference.G2WebServicePortType.getStudentData(getStudentDataRequest请求)中
在c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\G2TestApp\Service References\G2ServiceReference\G2WebServicePortTypeClient.getStudentData(ServiceRequest serviceReq)中的InetgrisG2TestApp.G2ServiceReference.G2WebServicePortTypeClient.getStudentData(ServiceRequest serviceReq)中:第2987行
在c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\G2TestApp\Program.cs中的InetgrisG2TestApp.Program.Main(字符串[]args)处:第57行}

您的WCF服务可能正在返回HTML。在本例中,您需要在服务端设置一个绑定来返回XML。然而,这是不可能的:如果是这样的话,请告诉我,我会编辑更多细节

更可能的原因是您的服务正在抛出一个错误,返回一个HTML错误页面。如果您需要详细信息,可以查看

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

编辑:


查看编辑后,您可以看到返回的完整错误。Apache无法告诉您要调用哪个服务,因此抛出了一个错误。一旦您有了正确的端点,服务就会正常工作-您被指向了错误的位置。很遗憾,我无法从可用的信息中判断正确的位置,但您的操作(当前为
null
!)或URL不正确

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

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


希望这有帮助。

我们使用IIS的Url重写扩展将所有HTTP请求重定向到HTTPS。当你打电话给服务员时
<endpoint address="http://localhost/WebService/WebOnlineService.asmx" 
<endpoint address="http://localhost:10593/WebService/WebOnlineService.asmx"
http://localhost:61277/Email.svc
HTTP Error 500.19 - Internal Server Error
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).