« Partial Methods: the Missing Pieces of Code Generation | Main | SOA.NET news on InfoQ »

27.04.07

WCF Dynamic Proxy

I’m a big fan of WCF XML Messaging, i.e. making use of the Message object and accessing the SOAP envelope directly. In my opinion this approach supports the loosely coupled nature of services best.

Although Untyped Services have no need for generated service proxies and they don’t rely on XML serialization, you have to provide the service contract (.NET interface). You might generate the interface from the published WSDL or write the code by hand. Either way the development of a service contract on the client side is annoying.

The WCF team at NetFx3 has published a WCF Dynamic Proxy, which relies on the WSDL URL in order to create a proxy for communication with a service:

1. Create the ProxyFactory specifying the WSDL URI of the service.

    DynamicProxyFactory factory = new DynamicProxyFactory(“http://localhost:8080/WcfSamples/DynamicProxy?wsdl”);

2. Browse the endpoints, metadata, contracts etc.
    factory.Endpoints
    factory.Metadata
    factory.Contracts
    factory.Bindings

3. Create DynamicProxy to an endpoint by specifying either the endpoint or
   contract name.
    DynamicProxy proxy = factory.CreateProxy(“ISimpleCalculator”);

    OR

    DynamicProxy proxy = factory.CreateProxy(endpoint);
4. Invoke operations on the DynamicProxy
    dobule result = (dobule)proxy.CallMethod(“Add”, 1d ,2d);

5. Close the DynamicProxy
    proxy.Close();

 

This is a great way of (really) decoupling your client (consumer) from the service (provider)!

Posted by Hartmut Wilms at 27.04.07 10:50

Trackback Pings

TrackBack URL for this entry:
http://www.innoq.com/movabletype/mt-tb.cgi/2468

Comments

Hi, i’m testing WCF Dynamic Proxy but i have a problem. When i create a DynamicProxyFactory i receive this error: “There was an error in importing the metadata”. Wsdl URL is http://webservices.dotnethell.it/codicefiscale.asmx?wsdl. Can you help me? This error is verified not only with wsdl url. Excuse my english

Posted by: marco at 29.02.08 00:35