views:

238

answers:

1

I have a number of WCF services on my internal network which are hosted by IIS 6 using the basicHttpBinding. There are several existing applications which use these services by using the dynamic proxy "CreateChannel()" method.

I'm building a mobile application which runs outside of our network, using a cellular connection, where it is important to minimize data usage, so i'm trying to use the netTcpBinding instead of any of the http bindings.

My idea is to build a "WCF Proxy", basically a service that runs on a server that is exposed to the outside, listens using a net.tcp binding, and converts/forwards the requests to the internal http services.

Right now the code is very simple, it looks about like this...

ChannelFactory factory=new System.ServiceModel.ChannelFactory<IFooService>("FooService",new System.ServiceModel.EndpointAddress("http://internalserver/FooService.svc");
IFooService fooService=factory.CreateChannel();

ServiceHost host = new ServiceHost(fooService, new Uri[] { new Uri("net.tcp://externalserver:50001/FooService")});

I realize that this is very naive code at this point, it doesn't account for faulted channels etc, but bear with me.

The issue I'm having is that calling GetType() on fooService (which here is a proxy generated by wcf) returns IFooService, not the class of the proxy. WCF doesn't like that when creating a new service host, and I get the error "'this' type cannot be an interface itself." on the last line.

Is this just a horrible Idea? If not what's the best way to get it running? Am I going to be forced into using the svcutil generated proxies?

+2  A: 

In current WCF 3.5, you have to do this yourself - see the excellent two-part article

by Michele Leroux Bustamante.

With WCF 4 - to be released with .NET 4, presumably in March 2010 - things will get a lot easier since WCF 4 will already include a base "RoutingService" class - see a Endpoint.TV video interview by Ron Jacobs on this topic.

Marc

marc_s
+1, excellent post.
Darin Dimitrov
That looks like exactly what I'm looking for. It's all about know what the right search keywords are! Thanks!
Brook