WCF : Client > Endpoint > Error : Invalid URI on working URL

WCF : Client > Endpoint > Error : Invalid URI on working URL

我正在设置一个 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>

给出的错误是:

Invalid URI: The format of the URI could not be determined.

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

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

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

因此您的过滤器应如下所示:

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

更多关于FilterData的内容属性,请参考以下内容link:

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