【问题标题】:Pass (proxy) SoapHeader through a WCF service to an ASMX service通过 WCF 服务将(代理)SoapHeader 传递给 ASMX 服务
【发布时间】:2011-07-05 12:27:02
【问题描述】:

我们有一个现有的 ASMX Web 服务 (.NET 2.0),我现在正在使用 WCF 和 .NET 4.0 创建一个新服务。

ASMX 服务通过SoapHeader 实现了自定义身份验证,看起来像这样,SecurityContextExtension 处理身份验证:

[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;
  }
}

新服务需要在现有 ASMX 服务上调用此方法,因此我将其作为服务引用添加到我的项目中。

CustomContextHeader 作为方法上的参数公开(我猜是通过 WCF 服务引用的魔力!),因此我从 WCF 服务调用 ASMX 如下所示:

[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
  }
}

正在访问新 WCF 服务的客户端也访问了现有的 ASMX,因此已经能够生成正确的 CustomContextHeader 并传递给 GetExisting 方法。

如果客户端要生成与 ASMX 相同的 CustomContextHeader,我该如何更改我的 WCF 服务以接受并提取它以通过参数传递给 ASMX?

我在 Google 上搜索并发现了很多关于 Message ContractsWCFExtras 的信息,但无法完全弄清楚如何实现这两种方法来实现我所需要的。我不希望添加像 WCFExtras 这样的其他依赖项,因此任何可以使用开箱即用的 .NET 4.0 功能的解决方案都将不胜感激!

【问题讨论】:

  • @Shevak 我面临一个相关问题。你可以帮助我……所以,写在这里。您能否分享一下,从 wcf 客户端作为“CustomContextHeader”传递什么,因为这个额外的 argumnet 显示为标题。我们是否必须创建名为“CustomContextHeader”的对象名称并在其中保留 tokenID 或相关属性并将其对象作为 argumnet 传递?请建议我。我不清楚在 ASMX 调用中应该通过什么作为标题参数,没有这样的 argumnet,我们只是设置了 TOKENID 字段,方法现在只有一个 argumnet“ID”,它显示了两个 argumnet - HEADER、ID 和 OUT PARAMETER 响应。

标签: .net c wcf soap asmx


【解决方案1】:

最终使用WCFExtras+

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-26
  • 1970-01-01
  • 2014-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多