相关疑难解决方法(0)

所有操作的WCF WSDL Soap Header

通过定义实现IContactBehavior和IWsdlExportExtension的属性并在服务合同上设置该属性,您可以轻松地将Soap Headers添加到wsdl(有关更多信息,请参阅http://wcfextras.codeplex.com/)

但是现在我需要在所有Operationcontracts的wsdl中设置Soap Header合约,这次我不能设置属性.

以下代码(从IWsdlExportExtension.ExportEndPoint调用)不起作用,但在从SoapHeaderAttributes调用时执行(执行IWsdlExportExtension.ExportContract)

foreach (OperationDescription operationDescription in context.ContractConversionContext.Contract.Operations)
{
   AddSoapHeader(operationDescription, "SomeHeaderObject", typeof(SomeHeaderObject), SoapHeaderDirection.InOut);                    
}

internal static void AddSoapHeader(OperationDescription operationDescription, string name, Type type, SoapHeaderDirection direction)
{
    MessageHeaderDescription header = GetMessageHeader(name, type);
    bool input = ((direction & SoapHeaderDirection.In) == SoapHeaderDirection.In);
    bool output = ((direction & SoapHeaderDirection.Out) == SoapHeaderDirection.Out);

    foreach (MessageDescription msgDescription in operationDescription.Messages)
    {
        if ((msgDescription.Direction == MessageDirection.Input && input) ||
            (msgDescription.Direction == MessageDirection.Output && output))
            msgDescription.Headers.Add(header);
    }
}

internal static MessageHeaderDescription GetMessageHeader(string …
Run Code Online (Sandbox Code Playgroud)

c# wcf wsdl

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

wcf ×1

wsdl ×1