2012-02-29 2 views
2

나는 비누 봉투에 추가 된 특정 네임 스페이스가 필요한 서비스를 호출하고 있습니다. 난 여분의 공간을 추가하는 뭔가를해야 할 경우, 예를 들어WCF에서 비누 봉투에 사용자 정의 네임 스페이스 추가

여기 내 샘플 일반 비누 메시지

이미 다른 목적으로 IDispatchMessageInspector, IClientMessageInspector을 구현하고
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sec="ANOTHER NAMESPACE THAT I WANT TO ADD" > 
     <s:Header> 

    </s:Header> 
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <xyz xmlns=""> 
    <customerId>2511</customerId> 
    </xyz> 
    </s:Body> 
    </s:Envelope> 

, 난 잘 모르겠어요.

이는 svcutil을 통해 또는 외부 참조를 추가하여 코드를 생성 한 경우

답변

0

, 다음을 수행 할 수 있습니다

[System.ServiceModel.ServiceContractAttribute(Namespace = "ANOTHER NAMESPACE THAT I WANT TO ADD", Name = "sec")] 
public partial class TheClassYouAreUsingForAClient { } 

이것은 당신이 당신의 생성 된 코드를 수정하지 않고 네임 스페이스를 추가 할 수 있도록해야한다.

+4

이 나를 위해 작동하지 않았다 :

나는 Message, MessageFormatterFormatMessageAttribute 구현을 포함 전체 과정을 설명하는 블로그 게시물을 썼다. – Nuzzolilo

0

사용자 정의 Message 구현의 일부로 네임 스페이스를 추가 할 수 있습니다. 여기에는 OnWriteStartEnvelope() 메소드가 포함되어 있으며 사용자 정의 네임 스페이스를 무시하고 추가 할 수 있습니다. 그런 다음 메시지를 MessageFormatter에 연결 한 다음 MessageFormatAttribute을 사용하여 특정 방법에 동작을 첨부합니다.

당신이 봉투에 네임 스페이스를 추가 할 수있는 네임 스페이스가 오버라이드 (override) Message 구현에있는 추가 주요 방법 : 다음이 최고 수준의 선언 다시 사용되면

protected override void OnWriteStartEnvelope(XmlDictionaryWriter writer) 
{ 
     writer.WriteStartElement("soapenv", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/"); 
     writer.WriteAttributeString("xmlns", "oas", null, "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); 
     writer.WriteAttributeString("xmlns", "v2", null, "http://www.royalmailgroup.com/api/ship/V2"); 
     writer.WriteAttributeString("xmlns", "v1", null, "http://www.royalmailgroup.com/integration/core/V1"); 
     writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); 
     writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");    
} 

봉투에 문서의 나머지 부분을 부착 네임 스페이스를 인라 인하지 않고 네임 스페이스를 인라인하지 않습니다. http://weblog.west-wind.com/posts/2016/Apr/02/Custom-Message-Formatting-in-WCF-to-add-all-Namespaces-to-the-SOAP-Envelope

관련 문제