I understand this is a basic topic but never done this before starting from wsdl.
I am being handed a wsdl file and a bunch of xsd with the types definitions. I don't have a clue if they were created from a WCF service (I guess so because of the split out format) but I do need to create a WCF service that implements the contract.
Question: How do I get the service contract interface?
I know about wsdl.exe and svcutil.exe - but not too familiar with what's what.
I guess after that all that's left is implementing the service contract.
Any help appreciated!
P.S. I had another question about this but I tried to put too much stuff in the same question - so let's keep it simple for now.
You have two choices:
Option 1: Use the svcutil.exe
utility on the command line. It should be installed in your C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin
directory (or something similar, depending on machine and OS you have)
Use svcutil -? for the list of all the many parameters. Basically, in its most simple form, use:
svcutil (name of your service).wsdl (name of your datafile).xsd
and that will create a corresponding (name of your service).cs
C# file with the service and data contracts, and a sample config file.
The resulting *.cs file (or *.vb, if you want VB.NET) will contain the service contract (the methods, resulting from the WSDL) and the data contracts (the data portion, coming from the XSD) for your service.
Option 2: Use the "Add Service Reference" dialog in Visual Studio (on the "References" node in your Solution Explorer) and just enter the file name of your WSDL file:
This will create a service reference, which is basically the same as the output from the svcutil.exe
utility - plus a few helper classes and files for Visual Studio.
Unfortunately, in both cases, the import will create a horribly overloaded config file which is probably one of the reasons lots of programmers think WCF is awfully complicated - it's really not, but these two import tools just do a horrendously bad job on creating the basic config for you.... don't let that scare you away!
If the Add Service Reference for the WSDL doesn't automatically convert all relevant and necessary XSD files, you might need to add those to your project, and then use something like XSD2Code to convert those to C# (or VB.NET) classes for you.
The wsdl.exe
is the deprecated utility to convert a WSDL file into a ASMX (ASP.NET webservice) stub - don't use that anymore, use svcutil.exe
or Visual Studio's Add Service Reference for WCF.
As for how to create a proper and minimal WCF config, check out the DotNet Rocks TV Show #122 with Miguel Castro entitled Extreme WCF. Miguel presents a great way to structure your WCF projects, and to create just as much config as is really needed (and thus can be understood a lot better than the generated mess by svcutil).