How to Generate a WSDL in c# without making a http request
Greetings, I want to write a unit test to make sure that our web services have not changed the WSDL from the last known published version. The reason for this is because any change to a object in the WSDL will cause clients using Apache Axis to fail. Even if all you do is add a not-requred property. So, if there is a change then the developer needs to be alerted because product management will need to communicate to the clients about the change so they can be ready to re-compile their stubs when the new WSDL is published.
So I was hoping to have something like this:
[Test]
public void TheWSDLHasNotChanged(){
XmlDocument currentWSDL = SomeMysteryServiceIDontKnowAbout.GetWSDLForWebServiceClass(typeof(UserService));
XmlDocument existingWSDL = new XmlDocument().Load("ExistingWsdl.wsdl");
Assert.That(currentWSDL, Is.Equal.To(existingWSDL));
}
For 开发者_Go百科obvious reasons I don't want to make a request to a web server (which may or may not even be running when running unit tests).
To generate WSDL's from assemblies:
For WCF use SvcUtil.exe. See this MSDN HowTo.
For ASP.NET use ServiceDescriptionReflector. See this guide: http://craigandera.blogspot.se/2004/10/generating-wsdl-without-aspnet_18.html
Sorry, I misunderstood your code snippet in my first answer.
I've created a tool which can generate a WSDL file from a compiled c# assembly (dll) which contains one or more WebServices. Normally you require a running service (IIS or other) which hosts the .asmx so that you can retrieve the WSDL using /MyWebService.asmx?wsdl
This tool generate a WSDL file using reflection to retrieve all information from an assembly (dll).
Download and sourcecode can be found at http://wsdlgenerator.codeplex.com
Any hints and tips are welcome !
--Stef
精彩评论