2017-04-11 1 views
0

작동중인 WCF 웹 서비스 집합을 .NET 4.6에 코딩하여 서버로 아웃 바운드 호출하고 있습니다. 그래서, 그들은 .EXE에서 실행되고 있습니다 (실제로는 결국 Windows 서비스로 실행됩니다).WCF 주소 지정 - WSA : TO 요소 제거

이 웹 서비스는 WS- 어드레싱 표준을 지원해야합니다 1.0 주소

W3C 웹 서비스 - 코어 http://www.w3.org/TR/2006/REC-ws-addr-core-20060509 WSA 그 표준 상태의 버전 그건

: 요소는 선택 사항입니다. 필요한 것은 WSA : TO 요소가 SOAP 출력에 전혀 나타나지 않는 것입니다. 그리고 WS-SECURITY를 사용해야하기 때문에 사용자 정의 SOAP 작성기를 작성하지 않고도이 작업을 수행하려고합니다. 내가 봤 한 등 등 내 바인딩 구성에서

내가 가진 :의 끝 지점으로

<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 : 요소가 여전히 발생하는 :(너트 쉘에 따라서

<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를 필요 S-Address 필드는 Action, Message ID, RelatesTo와 같지만 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> 

전 누구도 같은 전투에 안성맞춤입니다. 오랫동안 살아 남았고 SOAP은 멋진 조용한 죽음으로 죽을 수도 있습니다. 부자연 스러울만큼 가치가 있습니다.