c# - "Multiple filters matched."在 WCF 中对多个终结点使用相同的地址

标签 c# wcf service endpoint

因此,出于某些组织方面的考虑,我将最初的单一接口(interface)契约拆分为两个独立的契约。现在,我只有一个实现这两个接口(interface)的类,我想通过 WCF 将它们全部用作 REST 服务。 契约(Contract)如下:

第一:

[ServiceContract]
public interface INotification
{
    [OperationContract]
    [WebGet]
    XElement GetInfo(string appID);
    [OperationContract]
    [WebGet]
    void RegisterRID(string appID, string registrationID);
}

第二个:

[ServiceContract]
public interface IPlanning
{
    [OperationContract]
    [WebGet]
    XElement PlanTrip(string toDestination, string fromDestination, int year, int month, int day, int hour, int minute, string appID);
    [OperationContract]
    [WebGet]
    XElement PlanTripDelayed(string toDestination, string fromDestination, int year, int month, int day, int hour, int minute, string appID);
    [OperationContract]
    [WebGet]
    XElement PlanTripLoc(string toDestination, string fromLat, string fromLong, int year, int month, int day, int hour, int minute, string appID);
}

我的 app.config 看起来像这样:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
  <behaviors>
    <endpointBehaviors>
      <behavior name="RESTFriendly">
        <webHttp />
      </behavior>
    </endpointBehaviors>
  </behaviors>
    <services>
        <service name="TravelPlannerWebService.Domain.Entity.ETravelPlanner">
            <endpoint binding="webHttpBinding" bindingConfiguration="" contract="TravelPlannerWebService.Acquaintance.IPlanning" behaviorConfiguration="RESTFriendly" />
            <endpoint binding="webHttpBinding" bindingConfiguration="" contract="TravelPlannerWebService.Acquaintance.INotification" behaviorConfiguration="RESTFriendly" />
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:80" />
                </baseAddresses>
            </host>
        </service>
    </services>
</system.serviceModel>

问题是,每当我尝试使用两个接口(interface)时,都会出现错误。通过查看我的 app_tracelog.svclog(我在这里故意从 app.config 中删除了调试代码),我可以看到我收到以下错误:

消息:多个过滤器匹配。

堆栈跟踪:

System.ServiceModel.Dispatcher.EndpointDispatcherTable.LookupInCache(Message message, Boolean&amp; addressMatched)
System.ServiceModel.Dispatcher.EndpointDispatcherTable.Lookup(Message message, Boolean&amp; addressMatched)
System.ServiceModel.Dispatcher.ChannelHandler.GetDatagramChannel(Message message, EndpointDispatcher&amp; endpoint, Boolean&amp; addressMatched)
System.ServiceModel.Dispatcher.ChannelHandler.EnsureChannelAndEndpoint(RequestContext request)
           System.ServiceModel.Dispatcher.ChannelHandler.TryRetrievingInstanceContext(RequestContext request)
System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext)
System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)
System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult result)
System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
System.Runtime.InputQueue`1.AsyncQueueReader.Set(Item item)
System.Runtime.InputQueue`1.EnqueueAndDispatch(Item item, Boolean canDispatchOnThisThread)
System.Runtime.InputQueue`1.EnqueueAndDispatch(T item, Action dequeuedCallback, Boolean canDispatchOnThisThread)
System.ServiceModel.Channels.SingletonChannelAcceptor`3.Enqueue(QueueItemType item, Action dequeuedCallback, Boolean canDispatchOnThisThread)
System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action callback)
System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContextCore(IAsyncResult result)
System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContext(IAsyncResult result)
System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
System.Net.LazyAsyncResult.Complete(IntPtr userToken)
System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
System.Net.ListenerAsyncResult.WaitCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

我不知道如何解决这个问题。据我所知,根据以下指南,这是对多个端点使用相同类型的正确方法。有什么想法吗?

最佳答案

你可以使用下面的代码看看你是否仍然得到异常:

<service name="TravelPlannerWebService.Domain.Entity.ETravelPlanner">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="" contract="TravelPlannerWebService.Acquaintance.IPlanning" behaviorConfiguration="RESTFriendly" />
        <endpoint address="more" binding="webHttpBinding" bindingConfiguration="" contract="TravelPlannerWebService.Acquaintance.INotification" behaviorConfiguration="RESTFriendly" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:80" />
          </baseAddresses>
        </host>
      </service>

您不能让 2 个不同的端点监听同一地址。因此,我添加了 address 属性来区分它们。

在 IIS 中托管时,您的 URL 可能如下所示:

http://localhost/ApplicationVD/PlanTrip
http://localhost/ApplicationVD/PlanTripDelayed
http://localhost/ApplicationVD/PlanTripLoc
http://localhost/ApplicationVD/More/GetInfo
http://localhost/ApplicationVD/More/RegisterRID

关于c# - "Multiple filters matched."在 WCF 中对多个终结点使用相同的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8476748/

相关文章:

javascript - 使用数据进行 AJAX 后调用

c# - 悬停后如何更改按钮的颜色并单击xaml

c# - XPath对于带有不符合特定条件的子节点的所有节点?

c# - 没有 SVC 文件的 WCF 依赖注入(inject)

c# - WPF – 自定义控件 – 继承的 DependencyProperty 和 PropertyChangedCallback

c# - '使用类型 .. 不支持 NetDataContractSerializer' - 为什么要使用 NetDataContractSerializer?

wcf - "No destination configuration registered"- 使用 SAP nCo3(SAP .NET 连接器 3.0)的 WCF/SAP 集成

Delphi服务无法启动

service - 我应该用 Go 编写跨平台服务吗?

Android - 使用来自网络的数据通过服务更新小部件。最好的方法?