响应消息的内容类型 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)

查看:37
本文介绍了响应消息的内容类型 application/xml;charset=utf-8 与绑定的内容类型不匹配 (text/xml; charset=utf-8)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用独立应用程序使用 WCF Web 服务.我可以使用 Internet Explorer 查看此服务,也可以在 Visual Studio 服务引用中查看.

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.

这是我得到的错误

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?

这是我的配置文件

<?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:UserssDocumentsVisual Studio 2012ProjectsG2TestAppInetgrisG2TestAppService ReferencesG2ServiceReferenceReference.cs:line 2981
   at InetgrisG2TestApp.G2ServiceReference.G2WebServicePortTypeClient.getStudentData(ServiceRequest serviceReq) in c:UserssDocumentsVisual Studio 2012ProjectsG2TestAppG2TestAppService ReferencesG2ServiceReferenceReference.cs:line 2987
   at InetgrisG2TestApp.Program.Main(String[] args) in c:UserssDocumentsVisual Studio 2012ProjectsG2TestAppG2TestAppProgram.cs:line 57}

推荐答案

您的 WCF 服务可能正在返回 HTML.在这种情况下,您需要在服务端设置一个绑定来返回 XML.但是,这不太可能:如果,请告诉我,我会进行更详细的编辑.

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 is the case, let me know and I'll make an edit with more details.

更可能的原因是您的服务抛出错误,即返回 HTML 错误页面.你可以看看 这篇博文 如果你想了解详情.

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 post if you want details.

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

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.

看到您的编辑后,您可以看到返回的完整错误.Apache 无法判断您要调用哪个服务,因此会引发错误.一旦您拥有正确的端点,该服务就会正常工作 - 您指向了错误的位置.不幸的是,我无法从可用信息中得知 正确 位置是什么,但是您的操作(当前为 null!)或 URL 不正确.

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 right location is, but either your action (currently null!) or the URL is incorrect.

这篇关于响应消息的内容类型 application/xml;charset=utf-8 与绑定的内容类型不匹配 (text/xml; charset=utf-8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆