you can find the landing page here
Creating a proxy with Visual studio
If you're using VS 2008, (if you're not, ask yourself why.), you can easily add a proxy to an existing WCF service by right clicking the project node and using the "Add Service reference" option. Just one caveat here, you actually need a MEX endpoint to do this.
Right click on a project node in VS and choose add service refererence, which will give you something like this:
Using the Advanced button will give you access to some code generation parameters.
Hitting OK gives you
So, the interesting part here lies in the reference.cs file - as it contains:
- proxy class
- data contracts (client styled)
- service interface (client styled)
Sharing Data contracts
As indicated above the data contracts generated by the "Add service reference" process are "client styled", which means that they are created on the basis of what you have specified as data members and data contracts. While this is perfectly acceptable in most cases, and a *pure* implementation of SOA principles, sometimes you need something different.
WCF gives you the possibility to share your data contracts, just add the data contract assembly to the project and regenerate your service reference! Presto, your service reference is using the contracts defined in the referenced assembly. So now you have the same *type* of object in both client and server, which makes life a bit easier.
However, it also enables you to quickly run your project into the ground.. Imagine domain objects with behaviour that should run on the server, but which are shared.
Sharing Service contracts
You would imagine that you can do exactly the same with the service contracts, but unfortunately this is a no go... the proxy keeps on having his own contract version..
Imho, this is a serious bug, but more on it in a later post.
Creating a proxy manually
Unsurprisingly, you can also create a channel manually:
var proxy = ClientChannelFactory.CreateChannel<IService>();
proxy.Open();
//do some stuff
proxy.Close();
What you have to notice here is that you are reusing the service contract and the datacontracts from within their own assemblies, which is better than sliced bread!
0 comments:
Post a Comment