从VS2005移动到VS2008时,SoapHttpClientProtocol中的InnerChannel替换

时间:2009-12-09 10:53:20

标签: visual-studio-2008 soap visual-studio-2005

在我正在使用的项目中,我们正在使用SOAP公开的外部服务。在用于访问Visual Studio 2005生成的这些服务的代理类中,公开了成员InnerChannel,但Visual Studio 2008生成的代理类不是这种情况。

我正在尝试这样做,但当然会收到错误,因为该成员不存在:

using (new OperationContextScope(proxy.InnerChannel)) {
  OperationContext.Current.OutgoingMessageHeaders.Add(GetHeader());
  //...
}

1 个答案:

答案 0 :(得分:0)

SOAP似乎已在VS2008中完全重做。

要在VS2008中执行相同的操作,您需要创建一个实现SoapExtension的类:

public class classname : SoapExtension {
  public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) {
    throw new NotImplementedException();
  }

  public override object GetInitializer(Type serviceType) {
    return null;
  }

  public override void Initialize(object initializer) {}

  public override void ProcessMessage(SoapMessage message) {
    switch (message.Stage) {
      case SoapMessageStage.BeforeSerialize:
        var header = GetHeader(); // Returns a class implementing SoapHeader
        message.Headers.Add(header);
        break;
      case SoapMessageStage.AfterSerialize:
        break;
      case SoapMessageStage.BeforeDeserialize:
        break;
      case SoapMessageStage.AfterDeserialize:
        break;
    }
  }
}

在配置文件中注册该类:

....
  <webServices>
    <soapExtensionTypes>
      <add type="namespace.classname, namespace" priority="1" group="Low"/>
    </soapExtensionTypes>
  </webServices>
</system.web>