WCF: Calling a Basic WCF Service

So, you’ve build a WCF service and you’ve hosted it in IIS. Now you want to access this service. How? We’ll, we’re back to things being easy!

Using Visual Studio 2008, just go to Project, Add Service Reference. Type of URL of the service you built and choose a name for your new reference:

image

Once you click OK, you’ll be able to use your service just as though it was a class in your project:

Dim wcfTest As New svcTest.TestClient
Dim sTime As String = wcfTest.GetLocalTime(True)

If you’re still using .NET 2.0, you can also add a Web Service Reference, and consume your WCF service just as though it were a traditional ASP.NET Web Service using the ?wsdl metadata that’s generated.

As you can see, WCF Services are very easy to build and use. Configuring them takes a bit of learning, but the beauty of WCF is that you can write your service in one place, consume your service somewhere else, write code as though everything was happening in one program, and then use configuration files to connect them however you need.

Yes, it’s new. No, it’s not perfect. But it is very much a step in the right direction.

No comments:

Post a Comment


Copyright © 2010 Paul Guenette and Matthew Sleno.