문제

wsdl.exe로 만든 간단한 C# 웹 서비스 프록시 클래스가 있습니다. 원격 웹 서비스에서 메소드를 호출하고 있으며, 원하지 않는 WS-addressing 및 WS-Security 헤더가 포함되어 있습니다 (그리고 서버가 질식하고 있음). 다음은 원시 비누 요청의 예입니다.

<?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" 
  xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" 
  xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <soap:Header>
    <wsa:Action></wsa:Action>
    <wsa:MessageID>urn:uuid:22f12267-b162-4703-a451-2d1c5c5a619b</wsa:MessageID>
    <wsa:To>http://example.com/wstest</wsa:To>
    <wsse:Security>
      <wsu:Timestamp wsu:Id="Timestamp-5c9f0ef0-ab45-421d-a633-4c4fad26d945">
        <wsu:Created>2009-04-15T16:27:25Z</wsu:Created>
        <wsu:Expires>2009-04-15T16:32:25Z</wsu:Expires>
      </wsu:Timestamp>
    </wsse:Security>
  </soap:Header>
  <soap:Body>
    <Func1 xmlns="http://example.com">
      <arg_1 xmlns="">blah</arg_1>
      <arg_2 xmlns="">blah2</arg_2></arg_2>
    </Func1>
  </soap:Body>
</soap:Envelope>

하지만 나는 WS-Addressing/WS-Security에 신경 쓰지 않습니다. 나는 그것을 포함시키기 위해 아무것도하지 않았다. .NET WSE 3.0 패키지는 기본적으로 추가하는 것 같습니다. 이것들을 제거 할 수있는 방법이 있습니까? 이 섹션을 제거 할 수있는 프록시 객체에 속성이 보이지 않습니다. 난 노력 했어:

proxyObject.Addressing.Clear();
proxyObject.Security.Clear();

웹 서비스 메소드를 호출 할 때 널 참조 예외가 발생합니다.

비누 요청이 다음과 같이 보이기를 원합니다.

<?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:Header>
  </soap:Header>
  <soap:Body>
    <Func1 xmlns="http://example.com">
      <arg_1 xmlns="">blah</arg_1>
      <arg_2 xmlns="">blah2</arg_2></arg_2>
    </Func1>
  </soap:Body>
</soap:Envelope>

미리 감사드립니다

도움이 되었습니까?

해결책

글쎄, 나는 과거에 사용한 기술을 사용하게되었습니다. 구현하는 클래스를 만들었습니다 비누 필터 그리고 정책 여부 SOAP 요청이 전송되기 전에 RAW XML을 수정할 수 있습니다. 아래는 예입니다.

    public class MyPolicy : SoapFilter
    {
        public override SoapFilterResult ProcessMessage(SoapEnvelope envelope)
        {
            // Remove all WS-Addressing and WS-Security header info
            envelope.Header.RemoveAll();

            return SoapFilterResult.Continue;
        }
    }

    public class MyAssertion : PolicyAssertion
    {
        public override SoapFilter CreateClientInputFilter(FilterCreationContext context)
        {
            return null;
        }

        public override SoapFilter CreateClientOutputFilter(FilterCreationContext context)
        {
            return new MyPolicy();
        }

        public override SoapFilter CreateServiceInputFilter(FilterCreationContext context)
        {
            return null;
        }

        public override SoapFilter CreateServiceOutputFilter(FilterCreationContext context)
        {
            return null;
        }
    }

그런 다음 웹 서비스 프록시의 회의자에서 정책을 적용합니다.

/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "2.0.50727.1433")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]       
 [System.Web.Services.WebServiceBindingAttribute(Name="MyBinding", Namespace="http://example.com")]
    public partial class MyWebClient : WebServicesClientProtocol {

        // ... member variables here

        /// <remarks/>
        public MyWebClient()
        {
            this.Url = "http://example.com";           
            if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
                this.UseDefaultCredentials = true;
                this.useDefaultCredentialsSetExplicitly = false;
            }
            else {
                this.useDefaultCredentialsSetExplicitly = true;
            }

            // Apply policy here
            Policy policy = new Policy();
            policy.Assertions.Add(new MyAssertion());
            this.SetPolicy(policy); 
        }
  }

다른 팁

주소 지정 헤더를 제거하기 위해 앱 중 하나에서 아래 코드를 사용했습니다.

  public override void SecureMessage(SoapEnvelope envelope, Security security)
    {
       //remove addressing Header from envelope

        AddressingHeaders objAH = new AddressingHeaders(envelope);

        objAH.RemoveXml(envelope);


        //Add Wahtever security token you want to add.

        security.Tokens.Add(bla-bla-bla);

    }

나는 사용했다 SECUREMESSAGE 보안 토큰을 추가하고 싶었 기 때문에 기능하지만 동일한 코드를 사용할 수 있습니다. ProcessMessage 기능.

당신의 문제가 단순히 WSE를 사용하지 않음으로써 벤을 해결하지 못할 수도 있는지 궁금합니다.

이 페이지의 답변을 바탕으로 아래 코드를 추가하여 XML에서 특정 헤더 (Tagname)를 재귀 적으로 제거했습니다.

Public Overrides Function ProcessMessage(ByVal envelope As SoapEnvelope) As SoapFilterResult
    ' Remove all WS-Addressing and WS-Security header info
    RemoveTag(envelope.DocumentElement, "wsa:Action")
    RemoveTag(envelope.DocumentElement, "wsa:MessageID")
    RemoveTag(envelope.DocumentElement, "wsa:To")
    Return SoapFilterResult.[Continue]
End Function

Private Sub RemoveTag(ByVal XE As System.Xml.XmlElement, ByVal TagName As String)
    For Each N As XmlNode In XE
        If N.ChildNodes.Count > 0 Then
            RemoveTag(N, TagName)
        End If
        If N.Name = TagName Then
            XE.RemoveChild(N)
        End If
    Next
End Sub

이러한 주소 지정을 제거하는 가장 쉬운 방법을 찾았고 보안 헤더는 사용하도록 웹 서비스 구성을 변경하는 것입니다. BasicHttpBinding 대신에 WSHttp binding.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top