【问题标题】:Configuring endpoints for a web service with multiple interfaces为具有多个接口的 Web 服务配置端点
【发布时间】:2014-02-18 21:32:57
【问题描述】:

我需要能够为我创建的 Web 服务中的每个接口配置一个端点。 使用测试网络表单应用程序,我可以成功使用任一界面。但是当我尝试使用第二个接口添加第二个端点时,我收到以下错误:

以下是 Web 服务的 web.config 文件:

    <basicHttpBinding>
      <binding name="myBindingConfiguration1" closeTimeout="00:01:00" />
    </basicHttpBinding>
  </bindings>

    <services>
      <service behaviorConfiguration="PaymentServiceBehavior" name="PaymentService.PaymentService">
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="myBindingConfiguration1"
          name="PaymentInsecureService" contract="PaymentService.IPaymentService" />
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="myBindingConfiguration1"
          name="PaymentSecureService" contract="PaymentService.IPaymentSecureService" />
      </service>
    </services>

这是来自测试应用程序的 web.config 文件:

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IPaymentService" />
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:4567/Payment.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IPaymentService" contract="PaymentService.IPaymentService"
    name="PaymentInsecureService" />
  <endpoint address="http://localhost:4567/Payment.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IPaymentService" contract="PaymentService.IPaymentSecureService"
    name="PaymentSecureService" />
</client>

这是网络服务接口的代码:

namespace PaymentService
{
    [ServiceContract (Namespace = "name of namespace here")]
    public interface IPaymentSecureService
    {
        //Initiate a credit card authorization.
        [OperationContract(IsOneWay = true)]
        void Authorize(...12 parameters here...);

        more methods here....
    }
}

namespace PaymentService
{
    [ServiceContract (Namespace = "name of namespace here")]
    public interface IPaymentService
    {
        //Initiate a credit card authorization.
        [OperationContract(IsOneWay = true)]
        void Authorize(...13 parameters here....);

        more methods here...
    }
}

当其中一个接口方法名称相同但方法签名不同时,是否可以为每个接口设置一个端点?

我的配置文件有问题吗?

谢谢。

【问题讨论】:

  • 您是否尝试过在元端点上启用 httpGet?
  • 这是在 Web 服务文件中。

标签: c# web-services interface web-config


【解决方案1】:

我已经在其他 2 个论坛上发布了这个问题。尽管您应该能够拥有 2 个具有相同方法名称但签名不同的接口,并使用 2 个端点来访问每个接口,但我认为这是不可能的,除非您执行以下操作之一:

  1. 每个接口的命名空间都是唯一的。
  2. 重载方法的名称属性是唯一的。

我选择第一个选项是因为我正在更新旧代码并将 name 属性添加到方法中本质上会更改方法的名称。因此,在服务中使用此方法的所有客户端应用程序都需要进行更改。我想尽量减少对这些应用程序的更改,因此我更改了命名空间。

我认为这个命名空间属性是用来指向服务所在的位置的。根据微软文档和我有限的本地测试,情况并非如此。这是文档的摘录:

使用您控制的名称空间来标识您的 XML Web 服务。例如,您可以使用公司的 Internet 域名作为命名空间的一部分。许多 XML Web 服务名称空间看起来类似于 URL,但是,名称空间不必指向 Web 上的实际资源。 (XML Web 服务名称空间是 URI。)(统一资源标识符)。通过使用 XML 命名空间,您可以唯一地标识 xml 文档中的元素或属性。 xml Web 服务的服务描述在 xml 中,特别是在 WSDL 中。

我希望这可以帮助其他人解决这个问题...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-18
    • 2011-04-18
    • 2022-01-16
    • 1970-01-01
    相关资源
    最近更新 更多