2017-09-07 4 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> 

不幸にもこの解決策の原因を見つけることができません。私はちょうどこの質問を解決しています。

関連する問題