2011-06-30 99 views
0

我有客戶端上傳文件到我的服務器使用流媒體wcf服務。客戶端上的代碼是這樣的(忽略了一些細節):實現路由到我的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)); 
} 

我很困惑我怎樣才能將我的客戶端連接到路由服務。這是一個好方法嗎?謝謝。

回答