2011-12-26 193 views
14

Estoy alojando un servicio WCF en IIS 7.5 utilizando .NET 4.0. También tengo una aplicación WPF que estoy usando como cliente que fue desarrollada con Visual Studio 2010 y .NET 4.0. Agregué mi referencia de servicio y cuando intento llamar a una función, obtengo la siguiente excepciónWCF charset = utf-8 del mensaje de respuesta no coincide con el tipo de contenido del enlace (application/soap + xml; charset = utf-8)

El tipo de contenido application/xml; charset = UTF-8 del mensaje de respuesta no coincide con el tipo de contenido de la unión (application/soap + xml; charset = UTF-8)

Soy capaz de navegar con el servicio en un navegador web y mis enlaces parecen ser los mismos entre el cliente y el servicio (enlaces WsHttp).

Sé que hay muchos resultados de Google sobre este error, pero ninguno de ellos parecía ser relevante/ayuda a mi problema específico. Intenté instalar funciones de Activación que no sean HTTP, así como una gran variedad de otros pequeños trucos. ¿Alguien puede ayudar? Gracias

edición, aquí están mis configuraciones (que son bastante largo)

cliente

<?xml version="1.0"?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
     <basicHttpBinding> 
      <binding name="ContentSoap" 
       closeTimeout="00:01:00" openTimeout="00:01:00" 
       receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" 
       bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
       maxBufferSize="2147483647" maxBufferPoolSize="2147483647" 
       maxReceivedMessageSize="2147483647" 
       messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
       useDefaultWebProxy="true"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" 
           maxArrayLength="2147483647" 
           maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
       <security mode="None"> 
        <transport clientCredentialType="None" proxyCredentialType="None" 
           realm="" /> 
        <message clientCredentialType="UserName" algorithmSuite="Default" /> 
       </security> 
      </binding> 
      <binding name="OrderSoap" 
       closeTimeout="00:01:00" openTimeout="00:01:00" 
       receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" 
       bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
       maxBufferSize="65536" maxBufferPoolSize="524288" 
       maxReceivedMessageSize="65536" 
       messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
       useDefaultWebProxy="true"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" 
          maxArrayLength="16384" maxBytesPerRead="4096" 
          maxNameTableCharCount="16384" /> 
       <security mode="None"> 
        <transport clientCredentialType="None" proxyCredentialType="None" 
           realm="" /> 
        <message clientCredentialType="UserName" algorithmSuite="Default" /> 
       </security> 
      </binding> 
     </basicHttpBinding> 
     <netTcpBinding> 
      <binding name="NetTcpBindingEndpoint" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       transactionFlow="false" transferMode="Buffered" 
       transactionProtocol="OleTransactions" 
       hostNameComparisonMode="StrongWildcard" listenBacklog="10" 
       maxBufferPoolSize="2147000000" maxBufferSize="65536" maxConnections="10" 
       maxReceivedMessageSize="2147000000"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" 
        maxArrayLength="2147000000" maxBytesPerRead="4096" 
        maxNameTableCharCount="16384" /> 
       <reliableSession ordered="true" inactivityTimeout="00:01:00" 
           enabled="true" /> 
       <security mode="None"> 
       <transport clientCredentialType="Windows" 
          protectionLevel="EncryptAndSign" /> 
       <message clientCredentialType="Windows" /> 
       </security> 
      </binding> 
     </netTcpBinding> 
     <wsHttpBinding> 
      <binding name="WSHttpBinding_IInmateCanteenServiceWeb" 
       closeTimeout="00:01:00" openTimeout="00:01:00" 
       receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       bypassProxyOnLocal="false" transactionFlow="false" 
       hostNameComparisonMode="StrongWildcard" 
       maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 
       messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
       allowCookies="false"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" 
        maxArrayLength="16384" maxBytesPerRead="4096" 
        maxNameTableCharCount="16384" /> 
       <reliableSession ordered="true" inactivityTimeout="00:10:00" 
        enabled="false" /> 
       <security mode="Transport"> 
        <transport clientCredentialType="None" proxyCredentialType="None" 
          realm="" /> 
       </security> 
      </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint name="ContentSoap" 
      address="http://media.team.twvending.net/storeservices/content.asmx" 
      binding="basicHttpBinding" bindingConfiguration="ContentSoap" 
      contract="MediaPortContent.ContentSoap" /> 
     <endpoint name="OrderSoap" 
      address="http://media.team.twvending.net/storeservices/order.asmx" 
      binding="basicHttpBinding" bindingConfiguration="OrderSoap" 
      contract="MediaPortOrder.OrderSoap" /> 
     <endpoint name="NetTcpBindingEndpoint" 
      address="..." 
      binding="netTcpBinding" bindingConfiguration="NetTcpBindingEndpoint" 
      contract="WebCallBack.ICallbackService" /> 
     <endpoint name="WSHttpBinding_IInmateCanteenServiceWeb" 
      address="..." 
      binding="wsHttpBinding" 
      bindingConfiguration="WSHttpBinding_IInmateCanteenServiceWeb" 
      contract="InmateCanteenWeb.IInmateCanteenServiceWeb" /> 
     <endpoint name="WSHttpBinding_ICommAccountingBinding" 
      address="..." 
      binding="wsHttpBinding" 
      bindingConfiguration="WSHttpBinding_IInmateCanteenServiceWeb" 
      contract="CommAccountingWeb.ICommAccountingWeb" /> 
    </client> 
</system.serviceModel> 

y Servidor

<system.serviceModel> 
    <behaviors> 
     <endpointBehaviors> 
      <behavior name="httpBehavior"> 
       <!--<webHttp />--> 
      </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
      <behavior name="ServiceBehavior"> 
       <serviceCredentials> 
        <clientCertificate> 
        <authentication revocationMode="NoCheck" /> 
        </clientCertificate> 
        <serviceCertificate findValue="CN=secure.inmatecanteen.com" /> 
       </serviceCredentials> 
       <serviceMetadata httpsGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="true" /> 
      </behavior> 
      <behavior name="MexBehavior"> 
       <serviceMetadata httpsGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="true" /> 
      </behavior> 
      <behavior name="HttpMexBehavior"> 
       <serviceMetadata httpsGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="true" /> 
      </behavior> 
      <behavior name="BasicHttpMexBehavior"> 
       <serviceMetadata httpGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="true" /> 
      </behavior> 
      <behavior name=""> 
       <serviceMetadata httpsGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="true" /> 
      </behavior> 
     </serviceBehaviors> 
     </behaviors> 
     <serviceHostingEnvironment aspNetCompatibilityEnabled="false" 
           multipleSiteBindingsEnabled="true" /> 
     <bindings> 
     <wsHttpBinding> 
      <binding name="myWsHttpBinding" maxBufferPoolSize="2147483647" 
       maxReceivedMessageSize="2147483647" messageEncoding="Text"> 
       <readerQuotas maxDepth="32" maxStringContentLength="2147483647" 
         maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
         maxNameTableCharCount="2147483647" /> 
       <security mode="Transport"> 
        <transport clientCredentialType="None" /> 
       </security> 
      </binding> 
     </wsHttpBinding> 
     <webHttpBinding> 
      <binding name="myWebHttpBinding"> 
       <security mode="Transport"> 
        <transport clientCredentialType="None" proxyCredentialType="None" 
          realm="" /> 
       </security> 
      </binding> 
     </webHttpBinding> 
     <basicHttpBinding> 
      <binding name="myBasicHttpBinding" maxBufferPoolSize="2147483647" 
       maxReceivedMessageSize="2147483647"> 
       <readerQuotas maxDepth="32" maxStringContentLength="2147483647" 
         maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
         maxNameTableCharCount="2147483647" /> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service name="CommAccountingWeb.CommAccountingWeb" 
        behaviorConfiguration="HttpMexBehavior"> 
      <endpoint 
       address="" 
       behaviorConfiguration="httpBehavior" 
       binding="webHttpBinding" bindingConfiguration="myWebHttpBinding" 
       contract="CommAccountingWeb.ICommAccountingWeb" /> 
      <endpoint 
       address="mex" 
       binding="mexHttpsBinding" 
       contract="IMetadataExchange" /> 
      <host> 
       <baseAddresses> 
        <add baseAddress="..."></add> 
       </baseAddresses> 
      </host> 
     </service> 
     <service name="CommAccountingWeb.CommAccountingBasic" 
        behaviorConfiguration="BasicHttpMexBehavior"> 
      <endpoint 
       address="" 
       binding="basicHttpBinding" 
       bindingConfiguration="myBasicHttpBinding" 
       contract="CommAccountingWeb.ICommAccountingBasic" /> 
      <endpoint 
       address="mex" 
       binding="mexHttpBinding" 
       contract="IMetadataExchange" /> 
      <host> 
       <baseAddresses> 
        <add baseAddress="..." /> 
       </baseAddresses> 
      </host> 
     </service> 
    </services> 
</system.serviceModel> 
+0

Parece que su servicio está configurado para 'webHttpBinding' y, por lo tanto, solo devuelve XML, mientras que su cliente espera un mensaje SOAP XML .... ¿Puede mostrarnos las configuraciones del servidor y del lado del cliente? –

+0

Ver mi edición ... – tier1

+0

OK gracias por la edición, pero tiene tantos puntos finales de servicio y clientes conectando - ** cuáles ** está usando que causan este problema ?? ¿Cómo se ve el código del lado del cliente que está tratando de usar para llamar a una de esas funciones? –

Respuesta

18

Como sospechaba - su configuración del lado del cliente se ve como este :

<endpoint name="WSHttpBinding_ICommAccountingBinding" 
     address="https://secure.inmatecanteen.com/CommAccountingService/CommAccountingWeb.svc" 
     binding="wsHttpBinding" 
     bindingConfiguration="WSHttpBinding_IInmateCanteenServiceWeb" 
     contract="CommAccountingWeb.ICommAccountingWeb" /> 

Se espera wsHttpBinding - pero la dirección del lado del servidor se está conectando a es:

<service name="CommAccountingWeb.CommAccountingWeb" 
      behaviorConfiguration="HttpMexBehavior"> 
    <endpoint 
     address="" 
     behaviorConfiguration="httpBehavior" 
     binding="webHttpBinding" bindingConfiguration="myWebHttpBinding" 
     contract="CommAccountingWeb.ICommAccountingWeb" /> 
    <host> 
     <baseAddresses> 
      <add baseAddress="https://secure.inmatecanteen.com/CommAccountingService/CommAccountingWeb.svc"></add> 
     </baseAddresses> 
    </host> 
</service> 

y este extremo de servidor utiliza webHttpBinding.

Así, mientras el cliente espera una de SOAP mensaje XML (tipo de contenido: application/soap+xml; charset=utf-8), el punto final del lado del servidor es un punto final REST que devuelve (tipo de contenido: application/xml; charset=utf-8) llanura XML

Solución: es necesario asegurarse de que tanto el cliente como el el punto final del servidor utilizado estén sincronizados con respecto a los enlaces y la configuración.

0

Obtuve este problema después de agregar un método que devolvió una colección de instancias de una clase base que no tenía un atributo [KnownType] que se resolvería en una instancia concreta. Con el atributo [KnownType] en su lugar, el problema desapareció.

[ServiceContract] 
public interface IService { 
    [OperationContract] 
    IEnumerable<ItemBase> GetItems(); 
} 

[DataContract] 
// [KnownType(typeof(RealItemA))] <--- without these attributes you will get a problem 
// [KnownType(typeof(RealItemB))] 
public class ItemBase { 
} 

[DataContract] 
public class RealItemA : ItemBase { 
} 

[DataContract] 
public class RealItemB : ITemBase { 
} 
0

en mi caso mismo error fue causado por falta

[datacontract] 
[datamember] 

atributos de tipo de datos devuelto.

El mensaje de error fue realmente engañoso.

3

Me encontré con un error similar al crear un servicio de cliente a uno de los servicios web existentes del lado del servidor. Podría rectificarlo usando el protocolo de transporte SOAP 1.1 en el cliente. De alguna manera, soap 1.2 está dando/esperando un formato diferente. Este rastro vuelve a la diferencia entre BasicHttpBinding vs WebHttpBinding vs WsHttpBinding.

3

Como dice uno de los comentarios en this question, Agregue ?wsdl a la dirección del punto final de su cliente, y debería tener más suerte con el servicio. ?wsdl es importante, significa que el navegador acaba de obtener el "Lenguaje de descripción de servicios web" para el servicio y no llama al servicio.

Tuve el mismo problema y la adición de ?wsdl resolvió mi dolor de cabeza.

0

Asegúrese de que no ha realizado cambios en los enlaces, contratos y puntos finales generados en app.config al agregar la referencia de servicio.

Agregue MessageEncoding como Mtom en código .NET y luego verifique si aún recibe el mensaje.

He tratado de explicar la creación de un consumo de servicio WCF utilizando el protocolo de jabón por tanto wsHttpBinding y BasicHttpBinding y los problemas que enfrentan aquí: http://www.writeulearn.com/consume-wcf-soap-service-csharp/ Por favor, vaya a través de él.

0

Tengo este error debido a la versión diferente de Syste.Web.MVC DLL. Puede consultar la respuesta Here en otra pregunta de desbordamiento de pila.

Cuestiones relacionadas