Posts
414
Comments
232
Trackbacks
42
WCF Service Development Basics

Part of the fun of being a consultant is that the technology you use changes from day to day.  Recently it is WCF which, while knowing the concepts of since it came out I haven’t used up until now.

The nice thing is that it really isn’t any harder to develop for than a normal ASP.NET web service.  A couple of the attributes change and which project type you start with is different, but it is still message based services.

Just like the method of a web service needs a Webmethod attribute a method in a WCF service requires a OperationContract attribute.  The main difference is that you start by defining your operations in an interface.  Once you have an interface like the extract below you simply create an implementation class based on the interface.

[ServiceContract]
public interface IMyServices
{
[OperationContract]
MyCustomReturn GetMyData(MyDataRequest dataRequest);

To get your WSDL and its associated XSD to generate in a way that is intelligible by other developers you need to effectively use the DataContract and DataMember attributes.  The resulting class will look similar to the extract below.

[DataContract]
public class MyCustomReturn
{
[DataMember]
public string UserEmail;
[DataMember]
public string BusinessUnitId;
[DataMember]
public ClientAddressInfo ClientAddressInformation;

Once you have this base the rest of the development is straight up .NET.  The other thing you need to know is how to get at your WSDL and XSD.  The WSDL is the easy part.  Add “?wsdl” to the URL for your .svc file.

Finding the XSD isn’t that difficult.  If you look in the WSDL definition there is a tag for <wsdl:types>.  Within this tag you will find an <xsd:imports> that ties back to your service’s namespace.  Normally this is just adding a query string of “?xsd=xsd2” to your service URL.

Lastly you need to learn how to use the WCF Test Client.  The one way I have found to launch it is to make sure your service code file is active in the Visual Studio editor and hit F5.

image

This tool will allow you to do most of you basic testing of the service you just built.

Enjoy!

posted on Thursday, August 18, 2011 2:44 AM Print
Comments
No comments posted yet.

Post Comment

Title *
Name *
Email
Comment *  
 

Tim Murphy

Tim is a Solutions Architect for PSC Group, LLC. He has been an IT consultant since 1999 specializing in Microsoft technologies. Along with running the Chicago Information Technology Architects Group and speaking on Microsoft and architecture topics he was also contributing author on "The Definitive Guide to the Microsoft Enterprise Library".



I review for the O'Reilly Blogger Review Program



Technorati Profile

www.flickr.com
Tag Cloud