2017-09-07 67 views
2

我在我的項目中添加了一個服務引用。在MVC中生成SOAP頭文件C#

我需要在安全頭通過按以下

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

如何設置此。如果你看看我如何設置請求,是否有可能以標題的方式做同樣的事情。

安全性xsds嵌入在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); 

如何生成報頭部分???:

給服務操作的請求按以下被填充

你可以看到我通過安全標頭,因爲這是Web服務所要求的。

謝謝。

回答

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> 

不幸的是我找不到這個解決方案的來源了。我只是解決這個問題。