Browse DevX
Sign up for e-mail newsletters from DevX


Use WPF and WCF to Build Next-generation Applications : Page 3

Microsoft's new Expression tool allows designers to pass their output directly to developers in order to create rich XAML applications with an integrated toolset. Find out how to build a service using the Windows Communication Foundation and create a test client for it using "Cider," the plug-in for Visual Studio.NET that allows you to build XAML interfaces.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Creating the Service Proxy
To communicate with this service, your Avalon client will use a service proxy. This proxy needs to be generated based on the WSDL of the service. If you browse to the Service.svc file in the Web site, you'll see the address of the WSDL at the top of the screen (see Figure 2).

Generating a proxy is very straightforward use the svcutil.exe tool that comes as part of the WinFX SDK. You can find this tool in the C:\Program Files\Microsoft SDKs\Windows\v1.0\Bin directory. It's a good idea to add that to your path.

When you run svcutil.exe, passing it the WSDL URI as a parameter, it generates two files.

The first is called output.config. This contains the configuration information needed by the service model (the heart of WCF) to set up the communications pipeline. You should copy and paste the content of this file into your App.config file. Here's what it looks like:

<?xml version="1.0" encoding="utf-8"?> <configuration> <system.serviceModel> <bindings> <wsHttpBinding> <binding name="WSHttpBinding_IAdwService" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> <security mode="Message"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" /> </security> </binding> </wsHttpBinding> </bindings> <client> <endpoint address= "http://localhost:2107/avalondevx/Service.svc" binding="wsHttpBinding" bindingConfiguration= "WSHttpBinding_IAdwService" contract="IAdwService" name="default" /> </client> </system.serviceModel> </configuration>

The preceding XML configures the <system.ServiceModel> node, setting up a binding—this is how WCF creates the communications channel. It also configures the client communication, defining which binding it should use, and the underlying endpoint for the service that it will talk to.

The second file that svcutil.exe creates is called output.cs, which is the proxy implementation. This manages all the communication on your behalf. You simply create an instance of it in your client and call the operation contracts it exposes as local methods. If you're familiar with consuming Web services in C#, this works in exactly the same way.

Thanks for your registration, follow us on our social networks to keep up-to-date