簡體   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)

我試圖使用獨立應用程序使用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}

您的WCF服務有可能返回HTML。 在這種情況下,您將需要在服務端設置一個綁定以代替返回XML。 但是,這不太可能:如果這種情況,請告訴我,我將進行更詳細的編輯。

更有可能的原因是您的服務拋出了錯誤,該錯誤返回了HTML錯誤頁面。 如果需要詳細信息,可以查看此博客文章

tl; dr:錯誤頁面有幾種可能的配置。 如果您在IIS上托管,則需要從WCF服務的web.config文件中刪除<httpErrors>部分。 如果沒有,請提供您的服務托管方案的詳細信息,我可以進行修改以使其匹配。

編輯:

看完您的編輯后,您可以看到返回的完整錯誤。 Apache無法告訴您要調用哪個服務,並且由於這個原因拋出了錯誤。 一旦您擁有正確的端點,該服務將正常運行-您被指向錯誤的位置。 不幸的是,我無法從可用信息中得知正確的位置是什么,但是您的操作(當前為null !)或URL不正確。

當我遇到此錯誤時,我花費了數小時試圖找到解決方案。

我的問題是,當我去保存文件時,無意中擊中了web.config中的按鍵“ G”。 我只有一個散亂的角色坐在外面,所以web.config不知道如何解釋格式不正確的數據。

希望這可以幫助。

以防萬一...
如果您正在使用SoapUI模擬服務 (作為服務器),請從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->引發錯誤 響應消息的charset = utf-8

但是當我使用

System.Web.Mvc.dll版本4.0.0.0或更低版本 ->在我的項目中工作正常 ,沒有錯誤。

我不知道此DLL版本不同的原因,但是當我更改與您的WCF項目兼容的DLL版本時,它會正常工作。

當您在WCF項目中添加其他項目的引用並且此引用項目具有不同版本的System.Web.Mvc DLL或可能是任何其他DLL時,甚至會生成此錯誤。

就我而言,這只是web.config中的錯誤。

我有:

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

應該是:

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

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

這可能是web.config文件中的錯誤。

在瀏覽器中打開您的URL,例如:

http://localhost:61277/Email.svc

檢查是否有500錯誤。

HTTP Error 500.19 - Internal Server Error

在以下部分中查找錯誤:

配置錯誤

配置文件

嘗試在IIS中瀏覽WCF,看看它是否還可以正常運行,

就我而言,這是因為WCF的物理路徑錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM