我是WCF新手。我正在托管一个由第三方应用程序(TPA)调用的WCF服务。 TPA需要WCF服务响应,以自定义页眉和响应SOAP信封应该是这样的:如何在WCF服务响应中正确实现自定义soap 1.2头和WS-Addressing
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:stan="http://client/schema/framework/header/standardheaderresponse"
xmlns:sys="http://client/schema/framework/common/systemidentifier" >
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<stan:StandardHeaderResponse>
<stan:From>
<sys:Identifier>BUS</sys:Identifier>
<sys:Name>BuildingEvent</sys:Name>
<sys:Version>1</sys:Version>
</stan:From>
<stan:Timestamp>2013-03-15T03:05:41.000</stan:Timestamp>
<stan:CorrelationID>uuid:c12c9e48-8164-4074-9c8c-2b979804dbd2</stan:CorrelationID>
</stan:StandardHeaderResponse>
<wsa:Action>
http://client/service.buildingloc.event.BuildingEvent.SendEvent
</wsa:Action>
<wsa:MessageID>uuid:ab4c4001-f089-721c-aae6-f51ec37d3501</wsa:MessageID>
<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
<wsa:RelatesTo>uuid:de9a7007-f056-431c-aae6-f51ec37d3488</wsa:RelatesTo>
</soap:Header>
<soap:Body>
…
</soap:Body>
</soap:Envelope>
我的服务使用的是自定义WCF的结合如下:
var binding = new CustomBinding();
binding.Elements.Add(new TextMessageEncodingBindingElement() { MessageVersion = MessageVersion.Soap12WSAddressing10 });
binding.Elements.Add(new HttpTransportBindingElement());
要添加自定义的SOAP头我的回应我使用的是IDispatchMessageInspector,它看起来如下:
public void BeforeSendReply(ref Message reply, object correlationState)
{
reply.Headers.Add(new StandardHeaderResponse());
}
和的MessageHeader如下:
[MessageContract]
public class StandardHeaderResponse : MessageHeader
{
#region Overrides of MessageHeaderInfo
public override string Name
{
get { return GetType().Name; }
}
public override string Namespace
{
get { return "client/schema/framework/header/standardheaderresponse"; }
}
#endregion
#region Overrides of MessageHeader
protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
{
writer.WriteElementString("Key", "Value");
}
#endregion
}
但是当我运行的服务,并从我的测试客户端触发一个请求,我得到下面的输出提琴手
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:RelatesTo>urn:uuid:953e0b5b-44c6-4994-aae2-7710c31cb8f0</a:RelatesTo>
<StandardHeaderResponse>
<Key>Value</Key>
</StandardHeaderResponse>
</s:Header>
<s:Body>
...
</s:Body>
</s:Envelope>
这对TPA是如何期待它完全不同。我需要做些什么来使提琴手输出看起来更像TPA所期待的。为什么不将所有WS-Address元素(例如<wsa:Action>
,<wsa:MessageID>
和<wsa:RelatesTo>
)都渲染为标题的一部分。任何帮助将非常感激。
谢谢@Enes我会实施这个,看看它是否工作。 – Raghu 2013-04-10 07:13:33