给定 wsdl + xds 类型文件,如何创建存根 WCF Web 服务?
我知道这是一个基本主题,但在从 wsdl 开始之前从未这样做过。
我收到了一个 wsdl 文件和一堆带有类型定义的 xsd。我不知道它们是否是从 WCF 服务创建的(我猜是因为拆分格式),但我确实需要创建一个实现合同的 WCF 服务。
问题:如何获取服务契约接口?
我了解 wsdl.exe 和 svcutil.exe - 但不太熟悉它们是什么。 我想之后剩下的就是实施服务合同了。
任何帮助表示赞赏!
PS 我对此还有另一个问题,但我试图在同一问题中放入太多内容 - 所以现在让我们保持简单。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有两种选择:
选项 1:在命令行上使用
svcutil.exe
实用程序。它应该安装在您的C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin
目录中(或类似的目录,具体取决于您拥有的计算机和操作系统)使用 svcutil -?获取所有参数的列表。基本上,以最简单的形式使用:
,这将创建一个相应的
(服务名称).cs
C# 文件,其中包含服务和数据协定以及示例配置文件。生成的 *.cs 文件(或 *.vb,如果您需要 VB.NET)将包含您的服务的服务契约(方法,来自 WSDL)和数据契约(数据部分,来自 XSD) 。
选项 2:使用 Visual Studio 中的“添加服务引用”对话框(位于解决方案资源管理器中的“引用”节点上)并只需输入 WSDL 文件的文件名:
这将创建一个服务引用,它与 svcutil.exe 实用程序的输出基本相同- 加上一些 Visual Studio 的帮助器类和文件。
不幸的是,在这两种情况下,导入都会创建一个严重超载的配置文件,这可能是许多程序员认为 WCF 非常复杂的原因之一 - 事实上并非如此,但这两个导入工具在创建基本配置文件方面做得非常糟糕。为你配置......不要让那吓跑你!
如果 WSDL 的添加服务引用不会自动转换所有相关且必要的 XSD 文件,您可能需要将这些文件添加到您的项目中,然后使用类似 XSD2Code 为您将它们转换为 C#(或 VB.NET)类。
wsdl.exe
是已弃用的实用程序,用于将 WSDL 文件转换为 ASMX (ASP.NET Webservice) 存根 - 不要再使用它,请使用svcutil.exe
或Visual Studio 的 WCF 添加服务参考。至于如何创建正确且最小的 WCF 配置,请查看 Miguel Castro 的 DotNet Rocks TV Show #122,标题为 极端 WCF。 Miguel 提供了一种构建 WCF 项目的好方法,并创建与实际需要一样多的配置(因此可以比 svcutil 生成的混乱更好地理解)。
You have two choices:
Option 1: Use the
svcutil.exe
utility on the command line. It should be installed in yourC:\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:
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, usesvcutil.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).