给定 wsdl + xds 类型文件,如何创建存根 WCF Web 服务? [英] Given wsdl + xds type file, how do I create a stub WCF webservice?

查看:29
本文介绍了给定 wsdl + xds 类型文件,如何创建存根 WCF Web 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个基本主题,但在从 wsdl 开始之前从未做过.

I understand this is a basic topic but never done this before starting from wsdl.

我收到了一个 wsdl 文件和一堆带有类型定义的 xsd.我不知道它们是否是从 WCF 服务创建的(我猜是因为拆分格式),但我确实需要创建一个实现合同的 WCF 服务.

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.

问题:如何获得服务合同界面?

我知道 wsdl.exe 和 svcutil.exe - 但不太熟悉是什么.我想之后剩下的就是执行服务合同了.

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.

感谢任何帮助!

附言我对此有另一个问题,但我试图在同一问题中放入太多内容 - 所以现在让我们保持简单.

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.

推荐答案

您有两个选择:

选项 1: 在命令行上使用 svcutil.exe 实用程序.它应该安装在你的 C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin 目录(或类似的东西,取决于你拥有的机器和操作系统)

Option 1: Use the svcutil.exe utility on the command line. It should be installed in your C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin directory (or something similar, depending on machine and OS you have)

使用 svcutil -?对于所有许多参数的列表.基本上,以最简单的形式,使用:

Use svcutil -? for the list of all the many parameters. Basically, in its most simple form, use:

svcutil  (name of your service).wsdl (name of your datafile).xsd

这将创建一个相应的 (您的服务名称).cs C# 文件,其中包含服务和数据协定,以及一个示例配置文件.

and that will create a corresponding (name of your service).cs C# file with the service and data contracts, and a sample config file.

生成的 *.cs 文件(或 *.vb,如果您需要 VB.NET)将包含服务合同(方法,来自 WSDL)和数据合同(数据部分,来自 XSD)为您服务.

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.

选项 2: 使用 Visual Studio 中的添加服务引用"对话框(在解决方案资源管理器中的引用"节点上),然后输入 WSDL 文件的文件名:

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:

这将创建一个服务引用,它与 svcutil.exe 实用程序的输出基本相同 - 加上一些用于 Visual Studio 的帮助程序类和文件.

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.

不幸的是,在这两种情况下,导入都会创建一个可怕的重载配置文件,这可能是许多程序员认为 WCF 非常复杂的原因之一 - 事实并非如此,但这两个导入工具在以下方面做得非常糟糕为您创建基本配置.... 不要让它吓跑您!

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!

如果 WSDL 的添加服务引用没有自动转换所有相关和必要的 XSD 文件,您可能需要将它们添加到您的项目中,然后使用类似 XSD2Code 为您将它们转换为 C#(或 VB.NET)类.

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.

wsdl.exe 是不推荐使用的实用程序,用于将 WSDL 文件转换为 ASMX(ASP.NET Web 服务)存根 - 不要再使用它,使用 svcutil.exe 或 Visual Studio 的 WCF 添加服务参考.

The wsdl.exe is the deprecated utility to convert a WSDL file into a ASMX (ASP.NET webservice) stub - don't use that anymore, use svcutil.exe or Visual Studio's Add Service Reference for WCF.

至于如何创建适当且最小的 WCF 配置,请查看 Miguel Castro 的 DotNet Rocks 电视节目 #122,标题为 极限 WCF.Miguel 提供了一种很好的方式来构建 WCF 项目,并根据实际需要创建尽可能多的配置(因此可以比 svcutil 生成的混乱更容易理解).

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).

这篇关于给定 wsdl + xds 类型文件,如何创建存根 WCF Web 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆