El tipo de contenido application/xml;charset=utf-8 del mensaje de respuesta no coincide con el tipo de contenido del enlace (text/xml; charset=utf-8).

Estoy tratando de consumir un servicio web WCF utilizando una aplicación independiente. Soy capaz de ver este servicio utilizando Internet Explorer también capaz de ver en Visual studio referencias de servicio.

Este es el error que estoy recibiendo

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

¿Cómo puedo cambiar esto para utilizar el tipo de contenido correcto?

Aquí está mi archivo de configuración

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

aquí está la pila

{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}
Solución

Es posible que su servicio WCF devuelva HTML. En este caso, tendrá que configurar un enlace en el lado del servicio para devolver XML en su lugar. Sin embargo, esto es poco probable: si es el caso, hágamelo saber y haré una edición con más detalles.

La razón más probable es que tu servicio esté lanzando un error, que está devolviendo una página de error HTML. Puedes echar un vistazo a esta entrada de blog si quieres más detalles.

tl;dr: Hay algunas configuraciones posibles para las páginas de error. Si está alojando en IIS, querrá eliminar la sección `del archivoweb.config` del servicio WCF. Si no es así, por favor proporcione los detalles de su servicio de alojamiento escenario y puedo llegar a una edición para que coincida con ellos.

EDIT:

Después de ver su edición, se puede ver el error completo que se devuelve. Apache no puede saber a qué servicio quiere llamar, y está lanzando un error por esa razón. El servicio funcionará bien una vez que tenga el endpoint correcto - usted'está apuntando a la ubicación equivocada. Desafortunadamente, no puedo decir por la información disponible cual es la ubicación correcta, pero o bien su acción (¡actualmente null!) o la URL es incorrecta.

Comentarios (8)

Cuando me encontré con este error, pasé horas intentando encontrar una solución.

Mi problema era que cuando fui a guardar el archivo había pulsado accidentalmente la tecla "G" en el web.config. Tenía un Carácter rezagado que se había quedado fuera, así que el web.config no sabía cómo interpretar los datos formateados incorrectamente.

Espero que esto ayude.

Comentarios (0)

Utilizamos la extensión Url Rewrite para IIS para redirigir todas las peticiones HTTP a HTTPS. Al intentar llamar a un servicio que no utiliza seguridad de transporte en una dirección http://..., este es el error que aparecía.

Así que podría valer la pena comprobar si se puede golpear tanto el http y https direcciones del servicio a través de un navegador y que doesn't auto te reenvía con un código de estado 303.

Comentarios (0)