Remove WS-Addressing/WS-Security sections from WSE 3.0 Client request

后端 未结 5 1385
旧巷少年郎
旧巷少年郎 2020-12-09 23:27

I\'ve got a simple C# web service proxy class that I created with WSDL.exe. I am invoking a method on the remote web service, and it is including a bunch of WS-Addressing a

相关标签:
5条回答
  • 2020-12-09 23:33

    to remove the addressing header i used the below code in one of my app.

      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);
    
        }
    

    I used SecureMessage function because i wanted to add security tokens,but same code can be used in ProcessMessage function.

    0 讨论(0)
  • 2020-12-09 23:39

    I wonder if your problem might not also have ben resolved by simply not using WSE?

    0 讨论(0)
  • 2020-12-09 23:40

    Well, I ended up using a technique I have used in the past. I created classes that implement SoapFilter and PolicyAssertion which allow me to modify the raw XML of the SOAP request before it is sent. Below is an example:

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

    Then in your web service proxy's contructor you apply the policy:

    /// <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); 
            }
      }
    
    0 讨论(0)
  • 2020-12-09 23:43

    Based on the answer in this page, I added the code below to remove specific header (by tagname) recursively from XML.

    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
    
    0 讨论(0)
  • 2020-12-09 23:50

    I found the easiest way to remove these addressing and security headers was to change the web service configuration to use BasicHttpBinding instead of WSHttp binding.

    0 讨论(0)
提交回复
热议问题