首页 > 解决方案 > WCF:客户端 > 端点 > 错误:工作 URL 上的 URI 无效

问题描述

我正在设置 WCF 自托管解决方案以用作 WCF 路由器,但在启动服务时遇到了一些麻烦。

申请代码是

public class Program
{
    static void Main(string[] args)
    {

        ServiceHost routingHost = new ServiceHost(typeof(RoutingService));
        routingHost.Open();
        Console.WriteLine("Routing Service is running");
        Console.WriteLine("Press [Enter] to exit");
        Console.ReadLine();

        routingHost.Close();

    }
}

App.Config 服务部分是

<system.serviceModel>

<services>
  <service name="System.ServiceModel.Routing.RoutingService">
    <endpoint address="net.tcp://localhost:8009/proposalRouter"
              binding="netTcpBinding"
              contract="System.ServiceModel.Routing.IRequestReplyRouter" 
              name="proposalRouter" />
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceDebug includeExceptionDetailInFaults="true" />
      <routing filterTableName="proposalRoutingTable" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <netTcpBinding>
    <binding sendTimeout="00:45:00" maxReceivedMessageSize="2000000" />
  </netTcpBinding> 
</bindings>

<routing>
  <filters>
    <filter name="proposalFilter" filterType="EndpointAddress" filterData="proposalRouter"/>
  </filters>
  <filterTables>
    <filterTable name="proposalRoutingTable">
      <add filterName="proposalFilter" endpointName="defaultProposalService"/>
    </filterTable>
  </filterTables>
</routing>

<client>
  <endpoint address="http://localhost:64434/ProposalService.svc"
            binding="basicHttpBinding"
            contract="*"
            name="defaultProposalService"/>
</client>

给出的错误是:

无效的 URI:无法确定 URI 的格式。

我已将问题缩小到客户端 > 端点,但这是 svc 的 uri,不确定问题是什么

如果有人能告诉我我哪里出错了,我将不胜感激。

标签: c#.netwcf

解决方案


您的配置文件中的过滤器是错误的。当filtertype的值为address时,filterdata应该是一个URI。

在此处输入图像描述

所以你的过滤器应该是这样的:

    <filters>
            <filter name="proposalFilter" filterType="EndpointAddress" filterData="net.tcp://localhost:8009/proposalRouter"/>
    </filters>

有关 FilterData 属性的更多信息,请参考以下链接:

https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.routing.configuration.filterelement.filterdata?view=netframework-4.8


推荐阅读