开发者

Pass (proxy) SoapHeader through a WCF service to an ASMX service

We have an existing ASMX web service (.NET 2.0) and I am now creating a new s开发者_StackOverflow中文版ervice using WCF and .NET 4.0.

The ASMX service has implemented custom authentication via a SoapHeader and looks something like this, where SecurityContextExtension handles the authentication:

[WebService(Namespace = "http://tempuri.org/")]
public class ExistingWebService : WebService
{

  public CustomContextHeader CustomContextHeader{ get; set; }

  [WebMethod, SoapHeader("CustomContextHeader")]
  [SecurityContextExtension]
  public string GetExisting(int customerId)
  {
    // do stuff 

    return a string value;
  }
}

The new service needs to call this method on the existing ASMX service so I have added it as a Service Reference to my project.

The CustomContextHeader is exposed as a parameter on the method (I guess through the magic of WCF Service reference!) and so my call to the ASMX from my WCF service looks like this:

[ServiceContract]
public interface INewService
{
  [OperationContract]
  string GetNew(int myId);
}

public class NewService : INewService
{
  public string GetNew(int myId)
  {
    // do stuff

    using (var client = new ExistingWebServiceSoapClient())
    {
      var new = client.GetExisting(CustomContextHeader, myId);
    }

    // do more stuff
  }
}

The client which is accessing the new WCF service also accesses the existing ASMX so is already able to generate the correct CustomContextHeader and pass to the GetExisting method.

So if the client is going to generate the same CustomContextHeader as for the ASMX, how do I change my WCF Service to accept and extract it to pass along to the ASMX via the parameter?

I have Googled and discovered lots of information on Message Contracts and WCFExtras but cannot quite figure out how to implement either method to achieve what I need. I would prefer not to add another dependency like WCFExtras so any solution which can use out-of-the-box .NET 4.0 functionality will be greatly appreciated!


Ended up using WCFExtras+

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜