开发者

InnerChannel replacement in SoapHttpClientProtocol when moving from VS2005 to VS2008

In a project I'm working with we're using external services exposed by SOAP. In the proxy classes to access these services generated by Visual Studio 2005, the member InnerChannel was exposed, but this is not the case with the proxy classes generated by Visual Studio 2008.

I'm trying to do this, but of course get an error because the member doesn't exist:

using (new OperationContextScope(proxy.InnerChannel)) {
  Opera开发者_如何学运维tionContext.Current.OutgoingMessageHeaders.Add(GetHeader());
  //...
}


SOAP seems to have been completely redone in VS2008.

To do the same in VS2008 you need to create a class that implements 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;
    }
  }
}

And register that class in your config file:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜