views:

65

answers:

1

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)) {
  OperationContext.Current.OutgoingMessageHeaders.Add(GetHeader());
  //...
}
A: 

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>
svinto