我打算将WCFExtra用于soapheader。我已经添加了
<extensions>
<behaviorExtensions>
<!-- Declare that we have an extension called WSDL Extras-->
<add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
到我的服务配置文件中,我添加了 SoapHeaders 和 SoapHeader 属性...我在服务器端设置了与示例中完全相同的值 -
[OperationContract]
[SoapHeader("MyHeader", typeof(Header), Direction = SoapHeaderDirection.In)]
string In();
public string In()
{
Header soapHeader = SoapHeaderHelper<Header>.GetInputHeader("MyHeader");
if (soapHeader != null)
{
return soapHeader.Value;
}
return null;
}
在客户端我有
<metadata>
<wsdlImporters>
<extension type="WCFExtras.Soap.SoapHeaderImporter, WCFExtras" />
</wsdlImporters>
</metadata>
和
命名空间 Client.MyService { public partial class MyService { public Header MyHeader { get { return InnerChannel.GetHeader("MyHeader"); } 设置 { InnerChannel.SetHeader("MyHeader", value); } } } }
Console.WriteLine("Testing In()");
serviceClient.MyHeader = new Header() {Value = "in"};
string someValue = serviceClient.In();
Console.WriteLine("The return is = " + someValue);
我在调用中没有看到任何错误,但在服务端,我无法获取在客户端的 soapHeader 中传递的值。SoapHeader out 也会发生同样的事情。谁能帮我解决这个问题?我错过了什么?