How to read/parse soap header request in WCF service created in .Net Core 3.1

99封情书 提交于 2021-02-16 15:09:58

问题


I have created a poc WCF service and i am able to call that service using SOAP UI or Postman. But for some project work, i need to parse the below soap security header

SOAP Header

<soapenv:Header><wsse:Security 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"><wsse:UsernameToken wsu:Id="UsernameToken-5351BA8068B753C930158868612679914"><wsse:Username>test user</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">CS++k5OEqKsJByVPPmUqcBkAeoQ=</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">VK+Ilb/zy80lFbfHAAQupg==</wsse:Nonce><wsu:Created>2020-05-05T13:42:06.798Z</wsu:Created></wsse:UsernameToken></wsse:Security></soapenv:Header>

startup.cs file looks like below

public class Startup
    {
            public void ConfigureServices(IServiceCollection services)
             {

             services.AddScoped<ITestService, TestService>();          
             services.AddSoapServiceOperationTuner(new ServiceOperationTuner());
            }
 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {

            var binding = new BasicHttpBinding();
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Digest;
            app.UseSoapEndpoint<ITestService>("/Service.svc", binding, SoapSerializer.DataContractSerializer);
        }
}

ServiceOperationTuner.cs class has the code to get the HttpContext object as shown below. Here Tune menthod will be called for any request made to WCF service

public void Tune(HttpContext httpContext, object serviceInstance, OperationDescription operation)
        {
}

httpContext object hold all the header details but not the soapenv:Header.

Can anyone help me to parse this soapenv:Header request in .Net core ? Thanks in advance

来源:https://stackoverflow.com/questions/61618341/how-to-read-parse-soap-header-request-in-wcf-service-created-in-net-core-3-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!