2017-04-11 3 views
0

WCF Webサービスの作業セットは、.NET 4.6にコード化されています。これらはサーバーへの発信呼び出しです。したがって、それらは.EXEで実行されています(実際は最終的にはWindowsサービスとして実行されます)。WCFアドレス指定 - WSA:TO要素を削除する

これらのWebサービスは、WS-Addressingの標準をサポートする必要があります:1.0アドレッシング

W3CのWebサービス - コアをhttp://www.w3.org/TR/2006/REC-ws-addr-core-20060509 WSAその標準状態のバージョンということ

:要素にはオプションです。私が必要とするのは、WSA:TO要素をSOAP出力にまったく表示しないことです。私もWS-SECURITYを使用する必要があるので、カスタムSOAPライターを作成する必要はありません。私はGoogleで検索してきたなどなど、私のバインディング構成で

は私が持っている:のエンドポイントに

<binding name="MyServiceThatMustNotSendWSATO"> 
     <textMessageEncoding messageVersion="Soap12WSAddressing10" /> 
     <httpTransport /> 
    </binding> 

:私は利用可能textMessageEncodingのmessageVersionのすべての組み合わせを試してみた

<endpoint address="http://destinationserver.com/SomeServiceName/V1" 
    behaviorConfiguration="cliBeh" binding="customBinding" bindingConfiguration="MyServiceThatMustNotSendWSATO" 
    contract="SomeContract.SomeMethod" name="SomeEndPointName"> 
    <identity> 
     <dns value="somedns" /> 
    </identity> 
    </endpoint> 

、 WSA:TO要素はまだ生成されています。(

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> 
    <s:Header> 
     <a:Action s:mustUnderstand="1">tns:ServiceEntryStatusOut_V1</a:Action> 
     <a:MessageID>urn:uuid:88eda3c6-2b6a-4672-8e96-28f0e91c8b4c</a:MessageID> 
     <a:RelatesTo>urn:uuid:1f19a9f3-6e46-47cc-b190-cc7ef71dbc67</a:RelatesTo> 
     <a:To s:mustUnderstand="1">http://www.com/</a:To> 
    </s:Header> 

したがって、ナットシェルではWが必要ですアクション、メッセージID、RelatesToなどのS-Addressフィールドが含まれますが、To要素は含まれません。

答えて

0

のいずれかを持っていたことがありますか?プロジェクトですか?まあ、この問題は、私が直面している悪夢のいくつかの問題の一部です。しかし結局、私はそれらをすべて克服し、訴訟の解決策を得ました。素晴らしい解決策ではありませんが、決してそうなることはありませんでした。

とにかくこの特定の問題を解決するために、私はカスタムClientMessageInspectorクラスを使用して問題のあるフィールドを削除する必要がありました。そのクラスはカスタムビヘイビアエクステンションの一部です。私の質問では、私はこれをやりたくないと言います - 私の研究ではこれは単純に不可能です。デフォルトの.NET SOAP処理クラスをオーバーライドするには、カスタムクラスが必要です。

internal class ClientMessageInspector : IEndpointBehavior, IClientMessageInspector 
{ 
    public void Validate(ServiceEndpoint endpoint) 
    { 
    } 

    public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) 
    { 
    } 

    public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) 
    { 
     //throw new Exception("Exception in ApplyDispatchBehavior : "); 
    } 

    public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) 
    { 
     //throw new Exception("Exception in ApplyClientBehavior : "); 
     clientRuntime.ClientMessageInspectors.Add(this); 
    } 

    public object BeforeSendRequest(ref Message request, IClientChannel channel) 
    { 
     //throw new Exception("Exception in BeforeSendRequest : " + request.Headers.MessageId); 
     var message = request; 
     request = new MyCustomMessage(message); 
     return null; 
    } 

    public class MyCustomMessage : Message 
    { 
     private readonly Message _message; 

     public MyCustomMessage(Message message) 
     { 
      this._message = message; 
     } 

     protected override void OnWriteBodyContents(System.Xml.XmlDictionaryWriter writer) 
     { 
      MethodInfo dynMethod = _message.GetType().GetMethod("OnWriteBodyContents", BindingFlags.NonPublic | BindingFlags.Instance); 
      dynMethod.Invoke(_message, new object[] { writer }); 
     } 

     public override MessageHeaders Headers 
     { 
      get 
      { 
       // Remove wsa:To header 
       var index = this._message.Headers.FindHeader("To", "http://www.w3.org/2005/08/addressing"); 
       if (index > 0) 
       { 
        this._message.Headers.RemoveAt(index); 
       } 

       // Remove wsa:ReplyTo header 
       index = this._message.Headers.FindHeader("ReplyTo", "http://www.w3.org/2005/08/addressing"); 
       if (index > 0) 
       { 
        this._message.Headers.RemoveAt(index); 
       } 

       // Remove VsDebuggerCausalityData (only appears in Dev but here from convenience) 
       index = this._message.Headers.FindHeader("VsDebuggerCausalityData", "http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink"); 
       if (index > 0) 
       { 
        this._message.Headers.RemoveAt(index); 
       } 

       return this._message.Headers; 
      } 
     } 

     public override MessageProperties Properties 
     { 
      get { return this._message.Properties; } 
     } 

     public override MessageVersion Version 
     { 
      get { return this._message.Version; } 
     } 

    } 

    public void AfterReceiveReply(ref Message reply, object correlationState) 
    { 
     //throw new Exception("Exception in AfterReceiveReply : "); 
    } 
} 

必要なバインディングが複雑になるが、次のように終わる:

マイカスタムインスペクタのコードは次のように終わりました。重要なのは、カスタムビヘイビアエクステンションを使用して重い持ち上げをしてそれらのフィールドを削除することです。

<system.serviceModel> 

    <extensions> 

     <behaviorExtensions> 
     <add name="myBehaviorExtensionElement" 
      type="MySecurityBE.MyBehaviorExtensionElement, MySecurityBE, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> 
     </behaviorExtensions> 

    </extensions> 

    <bindings> 

     <customBinding> 

     <binding name="ServiceName_soap12" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" 
     sendTimeout="00:01:00" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" 
     maxReceivedMessageSize="65536" useDefaultWebProxy="true" allowCookies="false"> 
      <textMessageEncoding messageVersion="Soap12WSAddressing10" /> 
      <httpTransport maxReceivedMessageSize="2147483647" /> 
     </binding> 

     </customBinding> 

    </bindings> 

    <behaviors> 

     <endpointBehaviors> 
     <behavior name="cliBeh"> 
      <myBehaviorExtensionElement/> 
      <clientCredentials> 
      <clientCertificate storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" findValue="BradTestClientKey"/> 
      <serviceCertificate> 
       <defaultCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" findValue="localhost2"/> 
       <authentication certificateValidationMode="None" trustedStoreLocation="LocalMachine"/> 
      </serviceCertificate> 
      </clientCredentials> 
     </behavior> 
     </endpointBehaviors> 

    </behaviors> 

    <client> 

     <endpoint address="http://localhost.fiddler/TestRigClient_WS/Services/MyService" 
       binding="customBinding" bindingConfiguration="ServiceName_soap12" 
       contract="GenericFileTransferService.GenericFileTransfer" 
       name="ServiceName_soap12" behaviorConfiguration="cliBeh"> 
     <identity> 
      <dns value="localhost2"/> 
     </identity> 
     </endpoint> 


    </client> 

    <diagnostics> 
     <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="false" maxMessagesToLog="30000000" maxSizeOfMessageToLog="2000000"/> 
    </diagnostics> 

    </system.serviceModel> 

私は誰もが同じバトル幸運に直面したい。長いRESTが生きていて、SOAPはすばらしい静かな死によって死ぬでしょう。

関連する問題