Jenis konten application/xml;charset=utf-8 dari pesan respons tidak cocok dengan jenis konten binding (text/xml; charset=utf-8)

Saya mencoba untuk mengkonsumsi web service WCF menggunakan aplikasi stand alone. Saya dapat melihat layanan ini menggunakan Internet Explorer dan juga dapat melihat referensi layanan di Visual studio.

Ini adalah kesalahan yang saya dapatkan

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

Bagaimana cara mengubahnya agar menggunakan jenis konten yang benar?

Berikut ini adalah file konfigurasi saya

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

ini tumpukannya

{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}
Larutan

Mungkin saja layanan WCF Anda mengembalikan HTML. Dalam hal ini, Anda harus mengatur binding pada sisi layanan untuk mengembalikan XML. Namun, hal ini kecil kemungkinannya: jika memang demikian, beritahu saya dan saya akan mengedit dengan lebih detail.

Alasan yang lebih mungkin adalah bahwa layanan Anda melempar kesalahan, yang mengembalikan halaman kesalahan HTML. Anda dapat melihat posting blog ini jika Anda ingin detailnya.

tl;dr: Ada beberapa kemungkinan konfigurasi untuk halaman kesalahan. Jika Anda hosting di IIS, Anda harus menghapus bagian `dari fileweb.config` layanan WCF. Jika tidak, berikan detail skenario hosting layanan Anda dan saya dapat melakukan pengeditan untuk mencocokkannya.

EDIT:

Setelah melihat hasil edit Anda, Anda dapat melihat kesalahan penuh yang dikembalikan. Apache tidak dapat mengetahui layanan mana yang ingin Anda panggil, dan melemparkan kesalahan karena alasan itu. Layanan akan berfungsi dengan baik setelah Anda memiliki endpoint yang benar - Anda menunjuk ke lokasi yang salah. Sayangnya, saya tidak dapat mengetahui dari informasi yang tersedia apa lokasi yang benar, tetapi tindakan Anda (saat ini null!) atau URL-nya salah.

Komentar (8)

Ketika saya mengalami kesalahan ini, saya menghabiskan waktu berjam-jam untuk mencoba menemukan solusinya.

Masalah saya adalah ketika saya pergi untuk menyimpan file, saya secara tidak sengaja menekan key stroke "G" di web.config. Saya memiliki Karakter straggler yang hanya duduk di luar, sehingga web.config tidak tahu bagaimana menginterpretasikan data yang diformat dengan tidak benar.

Semoga ini membantu.

Komentar (0)

Kami menggunakan ekstensi Url Rewrite untuk IIS untuk mengarahkan semua permintaan HTTP ke HTTPS. Ketika mencoba memanggil layanan yang tidak menggunakan keamanan transport pada alamat http://..., ini adalah kesalahan yang muncul.

Jadi, mungkin ada baiknya memeriksa apakah Anda dapat menekan alamat http dan https layanan melalui browser dan itu tidak secara otomatis meneruskan Anda dengan kode status 303.

Komentar (0)