【问题标题】:implementing routing into my wcf service在我的 wcf 服务中实现路由
【发布时间】:2011-09-26 07:05:13
【问题描述】:

我有客户端使用带有流的 wcf 服务将文件上传到我的服务器。客户端的代码是这样的(省略一些细节):

NetTcpBinding binding = new NetTcpBinding();
EndpointAddress address = new EndpointAddress("net.tcp://" + ipAddress + ":5000/DataUploader");
ChannelFactory<IDataUploader> channel = new ChannelFactory<IDataUploader>(binding, address);
IDataUploader uploader = channel.CreateChannel();

try
{
    uploader.Upload(msg);
    ConsoleText.Record("The file was sent...\n");
}
catch (CommunicationException)
{
    ConsoleText.Record("The file was not sent...\n" + "Interrupted connection...\n");
}
finally
{
    uploadStream.Close();
    ((IClientChannel)uploader).Close();
}

我想在服务器和客户端之间实现路由服务,路由服务是这样的:

private static void ConfigureRouterViaCode(ServiceHost serviceHost)
{
    string clientAddress = "http://localhost:5000/DataUploader";
    string routerAddress = "http://localhost:5000/RouterService";

    Binding routerBinding = new WSHttpBinding();
    Binding clientBinding = new WSHttpBinding();

    serviceHost.AddServiceEndpoint(typeof(IRequestReplyRouter), routerBinding, routerAddress);

    ContractDescription contract = ContractDescription.GetContract(typeof(IRequestReplyRouter));
    ServiceEndpoint client = new ServiceEndpoint(contract, clientBinding, new EndpointAddress(clientAddress));

    RoutingConfiguration rc = new RoutingConfiguration();

    List<ServiceEndpoint> endpointList = new List<ServiceEndpoint>();
    endpointList.Add(client);

    rc.FilterTable.Add(new MatchAllMessageFilter(), endpointList);

    serviceHost.Description.Behaviors.Add(new RoutingBehavior(rc));
}

我很困惑如何首先将我的客户端连接到路由服务。这是一个好方法吗?谢谢。

【问题讨论】:

    标签: wcf routing


    【解决方案1】:

    你的方法是正确的。在客户端上,更改指向路由服务的地址,保留所有其他设置。建议你学习http://msdn.microsoft.com/en-us/library/ee517423.aspx或者找一些demo的路由实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      • 2011-07-16
      • 1970-01-01
      • 1970-01-01
      • 2020-12-30
      • 1970-01-01
      相关资源
      最近更新 更多