【问题标题】:Generating SOAP Headers in MVC C#在 MVC C# 中生成 SOAP 标头
【发布时间】:2018-02-15 19:35:01
【问题描述】:

我在我的项目中添加了一个服务引用。

我需要按以下方式传递安全标头

<soapenv:Header>
  <oas:Security>
      <oas:UsernameToken>
        <oas:Username>username</oas:Username>
        <oas:Password>!password</oas:Password>
     </oas:UsernameToken>
  </oas:Security>

如何设置。如果您查看我如何设置请求,是否可以以某种方式对标头执行相同操作。

安全 xsd 嵌入在 WSDL 中。

http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd

http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd

对服务操作的请求如下填充:

MyWebService.PortTypeClient client = new MyWebService.PortTypeClient();

MyWebService.SecurityHeaderType secHeader = new MyWebService.SecurityHeaderType();    

RetrieveOperationRequest detailsRequest = new RetrieveOperationRequest ();
detailsRequest.inputParam1 = "1234";

var result = client.RetrieveOperation(secHeader, detailsRequest);

如何生成 Header 部分???

您可以看到我传递了安全标头,因为这是 Web 服务所要求的。

谢谢。

【问题讨论】:

    标签: c# security model-view-controller soap wsse


    【解决方案1】:

    我设法找到了解决方案/解决方法。

    这是在 Web.config 文件中设置的。

     <client>
      <endpoint address="http://localhost:6478/service/1.0"
        binding="basicHttpBinding" bindingConfiguration="ServiceEndpointBinding"
        contract="TestService.PortType" name="ServiceEndpoint">
        <headers>
          <ns2:Security xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
            xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <ns2:UsernameToken>
              <ns2:Username>username</ns2:Username>
              <ns2:Password>!password</ns2:Password>
            </ns2:UsernameToken>
          </ns2:Security>
        </headers>
      </endpoint>
    </client>
    

    不幸的是,我再也找不到这个解决方案的来源了。我正在解决这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-13
      • 2017-06-12
      • 2012-04-01
      相关资源
      最近更新 更多