How to programmatically create WCF service by using existing WSDL file? - wcf

I have WSDL file and XSD files and need to programmatically create WCF service.
Programmatically means without using any utility tool such as SvcUtil.exe.
What's my problem here..??
I haven't found anything like that on internet.
I know how to create WCF service using ChannelFactory, but I don't know how to employ existing WSDL file in such a scenario.
There's something about using IXmlSerializable interface and its GetSchema, ReadXml and WriteXml methods, but I'm not sure how to use it.
Thank you in advance.
Goran

SvcUtil.exe doesn't do anything "magical" that you can't do yourself in your own code; It uses public WCF classes to process WSDL and XSD, you can use the exact same classes (for example, System.ServiceModel.Description.WsdlImporter), but unfortunately it's not very easy. Read http://msdn.microsoft.com/en-us/library/ms731768.aspx and its subtopics as a starting point. You can also open up SvcUtil.exe itself in Reflector to look at its code and see how it does certain things. I think there are also some open-source implementations of a "better svcutil", you can look at their code as well, unfortunately I can't remember any details at the moment.

Related

How to generate code for WCF with svcutil and xsd files?

I have a set of xsd files that define an XML message protocol for communications between devices. I'm planning to use WCF at one end. I'm hoping that there is a way to automate generation of classes based on the xsd files that I could use with WCF. Am I on the right track?
I'm aware of svcutil.exe and xsd.exe but a quick try gave me somewhat disappointing results. For example, "svcutil /dconly" command generated C# classes that contained only code related to xml serialization (e.g. WriteXml(), ReadXml(), etc.). There were no other properties generated.
This is not the only problem that I'm facing. Even if I succeed with generation of code from xsd I will still not be sure how to plug it into WCF.
Could someone please give some general idea how to deal with it? A simple example or a pointer to one would be greatly appreciated.
Thanks.
What you need to generate WCF service or client code using svcutil is a wsdl file. The wsdl describes the name of the service, witch methods will be available and references the xsd files witch contain the description of your data.

Create flattened WSDL using svcutil for wcf 4

I need to create a wsdl without the extras xsd files as external files, but have them all inside a single file. I need this because they will be imported by Delphi's WSDL importer, that is quite out-of-date. Can I do this using svcutil.exe? If it's not possible with svcutil, is there any way to do this? I have seen very old samples, based on WCF 3.5, but I don't know if they still apply.
Tks so much
This seems to be a popular topic this week. There are several articles on how to generate flattened wsdl but this article should get you started. The code in the article will work for WCF 4. For the actual code to create the behavior this (unrelated) blog post is pretty much all this needed.

Alternative to SvcUtil.exe?

I have been wrestling with SvcUtil all day, trying to get it to generate useful code for some IMS Enterprise Services (primarily Group Management Service, but there are others we need it to work for as well.) You can find the IMS service WSDL's here http://www.imsglobal.org/es/index.html.
I have come to the conclusion that SvcUtil is a useless afterthought from Microsoft that doesn't support the WSDL and XSD standards even in a half-assed way. It is incapable of generating a WCF service that conforms to the standard WSDL contracts that IMS uses AND functions at the same time. Despite generating compilable code from the following WSDL (http://www.imsglobal.org/services/gms/wsdl/imsGroupManServiceSync_v1p0.wsdl), observing the generated WSDL from the WCF service (?wsdl, ?wsdl=wsdl0, ?xsd=xsd0, etc.) shows that none of the operations exist, and only a fraction of the types that were generated in code are actually recognized by WCF. If we screw with the generated code, we can get something that sort of functions (we are using SoapUI to test), but then it no longer conforms to the contract, so its useless to the people who really need to call these services.
Are there any alternatives to SvcUtil? (Please don't suggest the built in Visual Studio "Add Service Reference" tool, that is just as useless as it uses the exact same code as SvcUtil.) We need something that will give us a degree of control over how code is generated from the WSDL contract, what files each part ends up in, which namespaces each code element ends up in, etc. The IMS contract imports both XSD types specific to the services defined in the WSDL, as well as XSD types that are common to all IMS services. We need to be able to generate different assemblies for those types, and reference them in the generated code (similar to how SvcUtil is apparently supposed to do it...but it doesn't seem to do what it says its documentation says it does at all.)
I have been a huge fan of WCF until now. It obviously works when you use only .NET/WCF services, but any time you try to use it in a standards-compliant, cross-platform environment, everything goes to shit.
Have you had a look at the WCF Proxy Generator on Codeplex? Based on who's behind it (Kate Gregory and Michele Leroux Bustamante), there's hope it might be useful - plus you get the sources, so you can adapt / tweak at your heart's content!
(haven't had the time to take a serious look at it myself - yet - it's on the endless "To-Do when I get around to it" list....)
Plus check out this blog post here by Pedram Rezaei showing how to influence the Visual Studio "Add Service Reference" step with your own custom code.
Sorry that I don't have time in full to reply to this but there is an answer to your question. There is an interface that you can implement called IWsdlImportExtension which has two methods that you will be interested in. They are:
GenerateContract() and GenerateOperation()
If you implement these methods, you can actually control the way SvcUtil pumps out code by adding or removing CustomAttributes and so on. You need to compile a dll with the interface in it and then point the SvcUtil configuration at the DLL and the interface.
Using this method, you can can for example add Xml documentation to your outputted proxies and so on. There are some interested articles around about this.

Generating RESTful API documentation from a WCF Service

I've recently started on a project to build out a RESTful API in WCF, and I'm going to need to expose documentation along with the API itself. I was hoping to leverage the XML code comments in my docs for this documentation.
But what I want to output is just the contracts that are exposed by the service: the endpoints and the JSON/XML object structures. Since I'm trying to create external documentation, I'm interested in any of the internals of my library, or how it ties into the .Net Framework (or even that it is .Net, for that matter).
What are my options for tools, to create these docs? I've heard that Sandcastle or Doxygen are good tools for generating docs from XML code comments, but can I filter away the classes and methods that I don't want to expose?
I understand this question was asked pre-.NET 4.0, but as of .NET 4.0, you can create a 'help page' as as described in WCF Web HTTP Service Help Page.
WCF 4.0 Example
[System.ComponentModel.Description("Triggers Method Name Behavior.")]
public void MethodName() {}
Sure, you can filter unwanted APIMembers with Sandcastle. This blogentry describes how. If you are new to Sandcastle, you might want to try out Sandcastle Help File Builder as well, which is basically a Sandcastle Frontend.
You could config doxygen to generate document from files speficied. Why not have a look a the documents of doxygen?

Adding comments to a WSDL output from WCF/.Net

based on the WSDL spec from W3 there is the possibility to add "wsdl:document" tags to the WSDL output so that people using that webservice have a better explanation/documentation about this webservice.
Does anybody know how to make WCF use these comments/descriptions, or how to write the code in C# that those comments are exported as part of the wsdl?
Thanks, Michael
It seems that the community project WCFExtras on GitHub provides a work-around the limitations of .NET 3.5.
If you're doing your design / coding in C# classes, adorned with [ServiceContract] and [OperationContract], then I don't know of any way to export documentation you might have on those classes and methods into the WSDL, unfortunately.
I was appalled by that too - I expected any /// comments on my classes and methods to show up in the WSDL - no luck :-(
Our solution now is this:
1) we create a basic "mockup" of our service interface with all operations in C#
2) we compile that into an assembly
3) we extract the metadata (WSDL, XSD) from that assembly and then throw away the C# "prototype"
4) we manually add comments (xs:annotation/xs:documentation) to the WSDL and XSD
5) from now on, the WSDL/XSD are the master - and we generate our interface from those descriptions
Cumbersome and annoying, but it works fairly ok for us.
I sure hope VS2010 / WCF 4.0 will bring us a bit more support in this area !!
Marc
http://msdn.microsoft.com/en-us/library/aa717040.aspx
I think this will do what you want but it only will work for .NET clients.
WCF won't do it on it's own unfortunately. There are extensibility points for WSDL generation that you can use to accomplish this at least partially: Look up the IWSDLExportExtension interface.
I have a small example on how to implement a simple WSDL export extension up on my website which might help you get started.
[WebService(Namespace = "XXXXXXXXXXXXX", **Description**="V0.2.42")]
Description put whatever you want in the .NET 4.0, not sure which versions... Probably a little late in answering, but answers seem more complex than required to add a blurb to WSDL only devs see.