2011-12-26 83 views
14

.NET 4.0を使用してIIS 7.5でWCFサービスをホストしています。また、Visual Studio 2010と.NET 4.0でビルドされたクライアントとしてWPFアプリケーションを使用しています。サービス参照を追加しました。関数を呼び出そうとすると、次の例外が発生します。応答メッセージのWCF charset = utf-8がバインディングのコンテンツタイプと一致しません(application/soap + xml; charset = utf-8)

コンテンツタイプapplication/xml;レスポンスメッセージのcharset = utf-8がバインディングのコンテンツタイプと一致しません(application/soap + xml; charset = utf-8)

私はウェブブラウザでこのサービスにナビゲートできます。私のバインディングはクライアントとサービス(WsHttpバインディング)の間で同じように見えます。

私はこのエラーに関するGoogleの結果がたくさんあることは知っていますが、どれも関連性がありませんでした/私の特定の問題に役立ちます。私は非HTTPアクティベーション機能のほか、さまざまな小さなトリックをインストールしようとしました。誰でも手伝うことができますか?あなたのクライアント側の設定は次のようになります - 私が疑われたようおかげ

編集は、ここに私のconfigs(彼らは非常に長いです)

クライアント

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

とサーバー

<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

これは、あなたのクライアントがSOAP XMLメッセージを期待している間に、あなたのサービスが 'webHttpBinding'用に設定されているだけでXMLを返すように聞こえます....サーバー側とクライアント側の設定を表示できますか? –

+0

私の編集を参照してください.... – tier1

+0

編集に感謝します。しかし、多くのサービスエンドポイントとクライアントが接続しています。クライアントサイドのコードはどのようなものか、それらの関数の1つを呼び出すために使用しようとしていますか? –

答えて

18

です:

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

これは、wsHttpBindingを期待 - それは、接続先のサーバー側のアドレスは次のとおりです。

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

と、このサーバーのエンドポイントがwebHttpBindingを使用しています。

だから、クライアントがSOAP XMLメッセージ(コンテンツタイプ:application/soap+xml; charset=utf-8)期待しながら、サーバー側のエンドポイントは、プレーンXML(コンテンツ・タイプ:application/xml; charset=utf-8)を返しRESTエンドポイントです

ソリューション:あなたをクライアントの両方が使用されているサーバーエンドポイントがバインディングと構成に関して同期していることを確認する必要があります。私は具体的なインスタンスに解決します[KnownType]属性を持っていませんでした基底クラスのインスタンスのコレクションを返した方法を追加した後

0

私はこの問題を得ました。 [KnownType]属性が設定されていると、問題は消えました。

[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

私の場合、同じエラーが返されるデータ型の属性

[datacontract] 
[datamember] 
の欠落によって引き起こされました。

エラーメッセージは本当に誤解を招いていました。

3

既存のサーバー側WebServiceのいずれかにクライアントサービスを作成しているときに、同様のエラーが発生しました。クライアント上でSOAP 1.1トランスポートプロトコルを使用して修正できます。どういうわけかsoap 1.2は異なるフォーマットを与えている/期待しています。このトレースは、BasicHttpBindingとWebHttpBindingとWsHttpBindingの違いに戻ります。

3

コメントの1つがthis questionに記載されているので、 クライアントのエンドポイントアドレスに?wsdlを追加すると、サービスにもっと幸運を祈るでしょう。 ?wsdlは重要です。つまり、ブラウザがサービスの「Web Services Description Language」を取得していて、サービスを呼び出していないことを意味します。

私は同じ問題を抱えていましたが、?wsdlが頭痛を解決しました。

0

サービス参照の追加時に、app.configで生成されたバインド、契約およびエンドポイントに変更を加えていないことを確認してください。

.NETコードでMessageEncodingをMtomとして追加し、まだメッセージが表示されるかどうかを確認してください。

私はwshttpbindingとbasichttpbinding、ここで直面した問題の両方にSOAPプロトコルを使用してWCFサービスの消費を作成する説明しようとした: http://www.writeulearn.com/consume-wcf-soap-service-csharp/ それを介して行ってください。

0

このエラーは、Syste.Web.MVC DLLのバージョンが異なるために発生します。回答Hereを別のスタックオーバーフローの質問で参照できます。