开发者

how do I run multiple WCF services on one port? [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

Hosting Multiple TCP WCF service Endpoints on single Port

I have 4 services running from one WCF service application, and it all works great if use 4 separate ports and is running on my local machine, hosted in a console app. That's fine for development, but now I want to move it to a Server 2008 machine on the intranet, and the IT boys aren't real happy about opening up a slew of ports on that machine.

I know I can run multiple services on the same port, but I can't seem to find anything telling me how to do so. Mostly, the first service starts up and then the second one fails to start.

Can anybody point me to a blog or article that explains how to do this?

I also need to figure out how to host the services开发者_运维百科 in WAS, but that may be a separate issue. I am using TCP protocol, if that makes any difference...

Thx, Dave


This looks like it could do the trick for you.

http://blogs.msdn.com/b/dkaufman/archive/2008/06/13/hosting-multiple-service-implementation-on-the-same-port-with-wcf.aspx

Which suggests that you need to set up the service behavior and endpoint correctly:

// Add behavior for Services - enable WSDL access
ServiceMetadataBehavior serviceABehavior = new ServiceMetadataBehavior();
serviceABehavior.HttpGetEnabled = true;
serviceABehavior.HttpGetUrl = new Uri("http://localhost:8080/ServiceA");
serviceAHost.Description.Behaviors.Add(serviceABehavior);

ServiceMetadataBehavior serviceBBehavior = new ServiceMetadataBehavior();
serviceBBehavior.HttpGetEnabled = true;
serviceBBehavior.HttpGetUrl = new Uri("http://localhost:8080/ServiceB");
serviceBHost.Description.Behaviors.Add(serviceBBehavior);

// Create basicHttpBinding endpoint at http://localhost:8080/ServiceA/  
serviceAHost.AddServiceEndpoint(serviceAContractType, new BasicHttpBinding(), 
"http://localhost:8080/ServiceA");
// Create basicHttpBinding endpoint at http://localhost:8080/ServiceB/  
serviceBHost.AddServiceEndpoint(serviceBContractType, new BasicHttpBinding(), 
"http://localhost:8080/ServiceB");

Or Net.TCP port sharing.

http://msdn.microsoft.com/en-us/library/ms734772.aspx

The HTTP.SYS model in which traffic for many different HTTP applications is multiplexed onto a single TCP port has become standard on the Windows platform. This provides a common point of control for firewall administrators while allowing application developers to minimize the deployment cost of building new applications that can make use of the network.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜