In this post I’m going to talk about easy WCF service proxy generation and about a great tool that can help you with that, WSCF.Blue. I’m also going to talk about using “Schema-first design and development”.
First a little background:
For my work I needed to create a proxy to a web service made with OSB (Oracle Service Bus) and Oracle SOA Suite. I had a url to start with, although the service was down at that moment. But the people who created it already gave me the WSDL and XSD. So I had to start “Schema-First”. Normally this is hard, because in Visual Studio you just can’t do “Add Service reference” and talk to the service like you do with WCF services. It mostly doesn’t work with non-.NET services. I found a tool, WSCF.blue, a Visual Studio Extension, that makes this much easier. You can download it here: WSCF.Blue. There’s a video at channel9 about the tool: http://channel9.msdn.com/Shows/Endpoint/endpointtv-WCF-Contract-First-with-WSCFblue
First I’m going to explain the difference between “Code-First” and “Schema-First”, then I’m going to show how I used WSCF.blue to generate a proxy for this Oracle service.
Difference between “Code-First and Schema-First”
The difference between those is explained very well in this MSDN Magazine article:
Schema-based Development with Windows Communication Foundation
This is a long article (which you definitely should read when you develop web services!). So I took the “Schema-First” and “Code-First” part from the article and present it here.
As a WS developer, your intention is to share your input/output system as a Web service — potentially across platform boundaries. The users of your Web service should not be worrying about your implementation details. Having access to your contract should be sufficient for someone else to consume it. Because Web services are platform-independent, we use interoperable, standards-based constructs like Web Service Definition Language (WSDL) and XML Schema (XSD) to define contracts. Modeling a contract involves modeling data, messages and the interface of your Web service.
First, you model your data contracts (that is, data structures) that are used to pass data between the clients and the service. Data contracts could either be simple or primitive types such as string, integer, double or complex, or domain-specific types such as Product, Employee or Itinerary.
In the code-first approach, you have the ability to use powerful declarative contract programming constructs provided by different Web service stacks (WCF, ASMX, JAX-WS, and so on). This way you can model them using your favorite programming language in your favorite editor. So instead of learning WSDL and XML Schema constructs, you can use programming constructs and data types you are already familiar with. The underlying WS stack takes care of the heavy lifting to generate WS contracts in its native form (WSDL and XSD). These declarative programming constructs also makes it a lot easier to put together a new Web service from scratch or expose an existing implementation as a service.
Easy WCF service Proxy generation for an Oracle service starting from the WSDL and XSD
First I downloaded and installed the extension from http://wscfblue.codeplex.com. They haven’t got a version for Visual Studio 2012 yet, so I installed it for Visual Studio 2010.
Then I created a WCF Service Library project: (File -> New -> Project -> Visual C# -> WCF -> WCF Service Library).
Then I added the directories with the WSDL / Schema to the WCF Services Library:
Then I selected the “CustomerService-concrete.wsdl”, right mouse-click -> WSCF.blue -> Generate Web Service Code.
Select “Client side proxy”, press [Generate]. Also, take a good look at the options you need.
This gave me the CustomerService-concrete.cs, which I could use in my WCF client (and it worked!). Which I can’t say of the svcutil.exe tool that you normally use for generating webservice proxy code… I even added the proxy code to an iOS app using Monotouch / C#, and it worked (with very little tweaking of the proxy code), but this is the subject of another blog article.
Some background why svcutil.exe doesn’t work sometimes:
In general, the default “Add service reference” option and the svcutil.exe tool work fine for simple .NET generated WCF services, but when you have anything else and the generated proxy code doesn’t work, you’re left on your own. At that moment you enter into a world of frustration.