3

政府機関が使用する予定の WCF サービスを開発しています。異なる契約会社がホストする同じサービスにアクセスするため、メッセージどのように表示されるかを正確に指定しています (したがって、各会社のサービスにアクセスするための URL のみを変更します)。

したがって、このメソッドの場合:

sbyte Execute(int Id1, short Id2, string Id3, string Id4, string Value)

彼らは、私たちが次の SOAP メッセージを正確に受け入れることを期待しています。

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http:/
/www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/
XMLSchema">
    <SOAP-ENV:Body>
        <m:Execute xmlns:m="http://tempuri.org/">
            <m:Id1>1</m:Id1>
            <m:Id2>2</m:Id2>
            <m:Id3>3</m:Id3>
            <m:Id4>4</m:Id4>
            <m:Value></m:Value>
        </m:Execute>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

そして、私たちの応答は次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <ExecuteResponse xmlns="http://tempuri.org/">
            <ExecuteResult>
                <res>0</res>
            </ExecuteResult>
        </ExecuteResponse>
    </soap:Body>
</soap:Envelope>

現在、binding="basicHttpBinding" を使用し、テスト クライアント (および WCF テスト クライアント ツール) を使用した現在のサービスのメッセージは次のようになります。

リクエスト:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/ISomeService/Execute</Action>
  </s:Header>
  <s:Body>
    <Execute xmlns="http://tempuri.org/">
      <Id1>0</Id1>
      <Id2>0</Id2>
      <Id3>0</Id3>
      <Id4>0</Id4>
      <Value>0</Value>
    </Execute>
  </s:Body>
</s:Envelope>

応答:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header />
  <s:Body>
    <ExecuteResponse xmlns="http://tempuri.org/">
      <ExecuteResult>1</ExecuteResult>
    </ExecuteResponse>
  </s:Body>
</s:Envelope>


だから、私の質問は次のとおりです。私のサービスが次のようなSOAPメッセージを使用するようにするには、何を変更すればよいですか

"<SOAP-ENV:エンベロープ xmlns:SOAP- ... > <SOAP-ENV:本体>"

使用する代わりに...

<s:封筒 .... > <s:ヘッダー />

いくつかのバインディング、カスタム構成などを試しましたが、同じように見せることはできませんでした。

これは、提案された customBinding を使用した現在の構成です。

  <system.serviceModel>
    <services>
      <service name="Test.SomeService">
        <endpoint binding="customBinding" bindingConfiguration="Soap11Binding"
          contract="Test.ISomeService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <bindings>
      <customBinding>
        <binding name="Soap11Binding">
          <textMessageEncoding messageVersion="Soap11" writeEncoding="utf-8">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          </textMessageEncoding>
          <httpTransport allowCookies="true" />
        </binding>
      </customBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

手がかりはありますか?ありがとう!

4

3 に答える 3

1

WCF サービスのバインドを に変更する必要basicHttpBindingSOAP v1.1ありwsHttpBindingますSOAP v1.2

ここを参照してください:SOAP 1.1vsSOAP 1.2

カスタム バインディングを作成して、必要なことを明示的に指定することもできますSOAP 1.1

<customBinding>  
    <binding name="Soap11Binding">  
        <textMessageEncoding messageVersion="Soap11" writeEncoding="utf-8">  
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"  
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />  
        </textMessageEncoding>  
        <httpTransport allowCookies="true" />  
    </binding>  
</customBinding>  
于 2012-07-04T05:34:34.840 に答える
1

カスタム メッセージ エンコーダーを使用して、メッセージを必要な形式に正確にフォーマットすることができます。これは、実装方法の URL です: http://msdn.microsoft.com/en-us/library/ms751486.aspx

WriteMessage メソッドでは、メッセージに必要な変更を行うことができます。

于 2012-07-05T07:44:27.167 に答える
0

wcf で応答を完全に制御するには、[MessageContract] を使用する必要があります。

[MessageContract] は単純なクラスで、さらに送信用の SOAP パケットとして使用されます。

要件を考慮すると、MessageContract を使用する必要があります。

于 2014-07-15T13:10:22.783 に答える