visual-studio 如何使用 WSDL 文件在 Visual Studio.NET 中创建 Web 服务?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3038785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I create a Web Service in Visual Studio.NET using a WSDL file?
提问by m-y
I'm trying to use a WSDL Top Down approach to create a Web Service in Visual Studio 2010.
我正在尝试使用 WSDL 自上而下的方法在 Visual Studio 2010 中创建 Web 服务。
I used Eclipse's WSDL GUI Editor to generate a WSDL file (CalculatorWSDL.wsdl) which uses the SOAP method for communication.
我使用 Eclipse 的 WSDL GUI 编辑器生成了一个 WSDL 文件 (CalculatorWSDL.wsdl),它使用 SOAP 方法进行通信。
I also used wsdl.exe to generate a C# file (Calculator.cs).
我还使用 wsdl.exe 生成了一个 C# 文件 (Calculator.cs)。
Now, I'm not sure what to do next. How do I actually use the Calculator.cs on the server and/or client?
现在,我不确定接下来要做什么。我如何在服务器和/或客户端上实际使用 Calculator.cs?
回答by marc_s
Actually, for WCF, you should not use wsdl.exe- use svcutil.exeinstead.
实际上,对于 WCF,您不应该使用wsdl.exe-svcutil.exe来代替。
When you use svcutil.exeon a WSDL, you should get a file myservice.cswhich contains an interface (the service contract) and quite possibly some data structures, too (data contracts).
当您svcutil.exe在 WSDL 上使用时,您应该得到一个文件myservice.cs,其中包含一个接口(服务契约)和很可能还有一些数据结构(数据契约)。
Use those to build your service - the service code needs to implement that interface and provide an implementation for those methods defined. That's basically the meat of the service application.
使用它们来构建您的服务 - 服务代码需要实现该接口并为定义的那些方法提供实现。这基本上是服务应用程序的主要内容。
See the Accessing Services Using a WCF Client Proxyfor more details - yes I know, the title is about generating WCF clients, but it works for services, too - you just convert the WSDL (and possibly XSD's) into a C# file and implement that interface defined in there.
有关更多详细信息,请参阅使用 WCF 客户端代理访问服务- 是的,我知道,标题是关于生成 WCF 客户端,但它也适用于服务 - 您只需将 WSDL(可能还有 XSD)转换为 C# 文件并实现它接口定义在那里。
You should definitely also read the Schema-based Development with WCFthat discusses this very topic - generate services and client from schemas/WSDL created ahead of time.
您绝对还应该阅读使用 WCF 进行基于架构的开发,其中讨论了这个主题 - 从提前创建的架构/WSDL 生成服务和客户端。
The same guy (Christian Weyer) is also the original author of a Visual Studio plugin to make contract-first development in WCF a lot easier - go grab it on Codeplex- it's totally free, totally with source - go nuts!
同一个人(Christian Weyer)也是 Visual Studio 插件的原作者,该插件使 WCF 中的契约优先开发变得更加容易——去Codeplex上获取它——它是完全免费的,完全有源代码——疯狂吧!

