【问题标题】:wcf - how to handle a service with multiple endpoints that share the same actionwcf - 如何处理具有共享相同操作的多个端点的服务
【发布时间】:2019-04-15 15:28:35
【问题描述】:

我在尝试启动我的服务时收到以下错误:

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

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

如果我更改其中一个的“操作”,它就会变得无法访问。

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

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

【问题讨论】:

    标签: wcf wcf-endpoint


    【解决方案1】:

    主要问题是双服务端点地址不能相同。您提供的配置具有相同的监听 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 消息会根据肥皂操作命名空间发送到正确的端点。
    简而言之,我们将不得不更改配置中的服务端点地址。 如果有什么可以帮助的,请随时告诉我。

    【讨论】:

    • 我的应用程序只需要有 1 个端点(例如 b2e.my.loc:8093)并且它是动态的。 (即每个用户基本上都可以定义自己的 URL 来使用)所以是否可以使用单个服务(MyFlightClass.ServiceFlight)来定义具有相同地址但用于不同合同的 2 个端点?
    • 一种可能是添加不同的listenuris(物理监听地址),使得服务器端的逻辑地址相同。但是在调用的时候,需要显式的给端点添加一个物理地址。 ClientViaBehavior via = new ClientViaBehavior(new Uri("localhost:57749/Service1.svc/efg")); client.Endpoint.EndpointBehaviors.Add(via); var result = client.GetData(34); docs.microsoft.com/en-us/dotnet/framework/wcf/samples/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-09
    • 1970-01-01
    相关资源
    最近更新 更多