2009-06-18 4 views
3

타사 웹 서비스를 사용하려고하므로 웹 서비스 코드에 액세스 할 수 없습니다. Visual Studio 2008에서 새로운 웹 사이트 프로젝트 (ASP 및 C#)를 만들고 웹 참조가 추가되었습니다 (웹 서비스가 아니므로 WCF 서비스가 아닌 것 같습니다 ...).Visual Studio 2008의 비누 요청에 비누 헤더 추가

문제는 웹 서비스 문서에서 각 비누 요청을 다음 봉투 및 헤더와 함께 보내야한다는 것을 알고 있습니다. 제 비누 요청에이를 추가하는 방법을 알려주시겠습니까? Visual Studio 2008의 클라이언트에서 웹 서비스 소스 및 웹 서비스 프록시에 대한 액세스 권한이 없기 때문에 웹 서비스 소스 또는 프록시를 수정해야하는 모든 솔루션이 필요합니다. 임시 파일 만!

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
<soap:Header> 
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" soap:mustUnderstand="1"> 
<wsse:UsernameToken xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
<wsse:Username>[email protected]</wsse:Username> 
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Ima5tatto</wsse:Password> 
</wsse:UsernameToken> 
</wsse:Security> 
</soap:Header> 
<soap:Body xmlns:ns2="http://neighbourhood.statistics.gov.uk/nde/v1-0/discoverystructs"> 
<ns2:AreaAtLevelElement> 
<AreaIdWithLevelType> 
<AreaId>276704</AreaId> 
<LevelTypeId>12</LevelTypeId> 
</AreaIdWithLevelType> 
</ns2:AreaAtLevelElement> 
</soap:Body> 
</soap:Envelope> 

답변

3

당신은 정적 endpoint 요소에 headers 요소를 사용하여 구성 파일의 메시지에 헤더를 추가 할 수 있습니다. headers 요소의 각 하위 요소는 메시지 헤더에 그대로 복사됩니다.

0

저는이 동일한 문제로 어려움을 겪고 있으며, 지금까지는 SOAP 헤더를 얻을 수 있도록 message inspector을 작성했습니다.하지만 wsse : 보안 기능을 수행 할 필요없이이를 얻는 방법을 잘 모르겠습니다. 수동으로. wsse : security stuff를 만들기 위해 WS-Security 스키마 (SAML 스키마는 물론)를 사용할 수 있기를 원합니다 ...

내 메시지 관리자 코드의 가치는 다음과 같습니다. 이 스레드에 게시 할 것입니다. 여기

client.Endpoint.Behaviors.Add(new CustomBehavior()); 
msgOutput = client.ProvideAndRegisterDocumentSetXDR(msgInput); 

그리고 메시지 관리자 및 사용자 정의 동작입니다 : 내가 클라이언트에 동작을 추가 할 경우 여기에

이야

public class CustomMessageInspector : System.ServiceModel.Dispatcher.IClientMessageInspector 
{ 
    public void AfterReceiveReply(ref WCF.Message reply, object correclationState) 
    { 
    } 

    public Object BeforeSendRequest(ref WCF.Message request, IClientChannel channel) 
    { 
     MessageHeaders headers = new MessageHeaders(MessageVersion.Soap11WSAddressing10); 
     MessageHeader header = MessageHeader.CreateHeader("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", ""); 
     request.Headers.Add(header); 
     return null; 
    } 
} 


public class CustomBehavior : System.ServiceModel.Description.IEndpointBehavior 
    { 
     public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) 
     { 
     } 

     public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRunTime) 
     { 
      CustomMessageInspector inspector = new CustomMessageInspector(); 
      clientRunTime.MessageInspectors.Add(inspector); 
     } 

     public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) 
     { 
     } 

     public void Validate(ServiceEndpoint endpoint) 
     { 
     } 
    } 
+1

읽기 [자주 묻는 질문] (http://stackoverflow.com /자주하는 질문). 토론 포럼이 아닙니다. 너 자신의 질문을한다. 우리는 여기에 "답장"을하지 않는다. 또한, 그는 "웹 참조"를 사용하고 있다는 것에주의하지 않기 때문에 -1. –