c# - 如何在不发出http请求的情况下在c#中生成WSDL [英] How to Generate a WSDL in c# without making a http request
问题描述
您好,我想编写一个单元测试,以确保我们的 Web 服务没有更改上次已知发布版本的 WSDL.这样做的原因是因为对 WSDL 中对象的任何更改都会导致使用 Apache Axis 的客户端失败.即使您所做的只是添加一个不需要的属性.因此,如果有更改,则需要提醒开发人员,因为产品管理需要与客户就更改进行沟通,以便他们可以在新的 WSDL 发布时准备好重新编译其存根.
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));
}
出于显而易见的原因,我不想向 Web 服务器发出请求(在运行单元测试时可能会运行,也可能不会运行).
For 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).
推荐答案
从程序集生成 WSDL:
对于 WCF,请使用 SvcUtil.exe.请参阅此 MSDN HowTo.
对于 ASP.NET,使用 ServiceDescriptionReflector.请参阅本指南:http://craigandera.blogspot.se/2004/10/generate-wsdl-without-aspnet_18.html
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.
这篇关于c# - 如何在不发出http请求的情况下在c#中生成WSDL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!