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

后端 未结 5 1388
旧巷少年郎
旧巷少年郎 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: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:

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

提交回复
热议问题