wcf-如何使用共享同一操作的多个端点处理服务

时间:2019-04-15 15:28:36

标签: wcf wcf-endpoint

尝试启动我的服务时出现以下错误:

Could not start the Service: System.InvalidOperationException: This service has multiple endpoints listening at 'https://b2e.my.loc:8093/' which share the same initiating action 'http://localhost:8080/kestrel/AirService'.  As a result, messages with this action would be dropped since the dispatcher would not be able to determine the correct endpoint for handling the message.  Please consider hosting these Endpoints at separate ListenUris.

我们得到了一个使用第三方WSDL来搜索和预订航班的应用程序。

,我们还有另一个winform应用程序,该应用程序从上述wsdl

生成生成的reference.cs

我们的想法是创建一个“模拟器”,因此实际上不是在调用真实的WSDL,而是在调用模拟器本身并生成我们需要的数据(某种模拟)

考虑以下由WSDL生成的reference.cs文件:

namespace FlightWCF
{
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(Namespace = "", ConfigurationName = "FlightWCF.ISearch")]
    public interface ISearch
    {
        [System.ServiceModel.OperationContractAttribute(Action = "http://localhost:8080/kestrel/AirService", ReplyAction = "*")]
        FlightWCF.serviceResponse1 service(FlightWCF.serviceRequest1 request);
    }


    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(Namespace = "", ConfigurationName = "FlightWCF.IReserve")]
    public interface IReserve
    {
        [System.ServiceModel.OperationContractAttribute(Action = "http://localhost:8080/kestrel/AirService", ReplyAction = "*")]
        FlightWCF.serviceResponse6 service(FlightWCF.serviceRequest6 request);
    }   
}

这是我的app.config的一部分

<service name="MyFlightClass.ServiceFlight">
    <endpoint address="" binding="basicHttpBinding"  bindingConfiguration="basicSecureHttpBindingConfiguration" contract="FlightWCF.ISearch" />
    <endpoint address="" binding="basicHttpBinding"  bindingConfiguration="basicSecureHttpBindingConfiguration" contract="FlightWCF.IReserve" />
</service>

这是使用上述代码的服务:

namespace MyFlightClass
{

    class  ServiceFlight :  ISearch, IReserve
    {
        public FlightWCF.serviceResponse1 service(FlightWCF.serviceRequest1 request)
        {
            //DO SOMETHING
        }

        public FlightWCF.serviceResponse6 service(FlightWCF.serviceRequest6 request)
        {
            //DO SOMETHING
        }
    }
}

问题在于两个服务都使用相同的“操作”。

如果我更改其中一个的“动作”,将无法访问。

我找不到有关如何配置具有两个具有不同合同但执行相同操作的端点的服务的任何数据。

我不清楚“请考虑在单独的ListenUris上托管这些端点”的建议。

1 个答案:

答案 0 :(得分:0)

主要问题是双服务端点地址不得相同。您提供的配置具有相同的监听Uri。

<service name="MyFlightClass.ServiceFlight">
    <endpoint address="" binding="basicHttpBinding"  bindingConfiguration="basicSecureHttpBindingConfiguration" contract="FlightWCF.ISearch" />
    <endpoint address="" binding="basicHttpBinding"  bindingConfiguration="basicSecureHttpBindingConfiguration" contract="FlightWCF.IReserve" />
</service>

因此,由于操作名称重复,因此该操作具有相同的名称空间。但是SOAP消息会根据soap操作名称空间发送到正确的端点。
简而言之,我们必须在配置中更改服务端点地址。 随时让我知道是否有什么可以帮助您的。