大型/复杂模式 (HR-XML/OAGIS) 的 WCF 代码生成 - 有替代方案吗?

发布于 2024-08-25 00:23:03 字数 717 浏览 4 评论 0 原文

感谢您的阅读。

我正在基于预定义的规范 (HR-XML 3.0) 实现 WCF 服务。因此,我从架构开始,然后回到代码。本规范提供了许多与我的实现相关的大型 Schema 文档(其中导入了更多 Schema 文档)。

我可以通过提供“主”和“支持”xsd 文件作为参数,使用 xsd.exe 生成代码。但有几个问题,我想知道这是否是正确的方法。

  • 几乎有数百个类 - 代码文件大小为半兆
  • 重复类(例如 Type、Type1 - 两者都表示相同类型)
  • 有声明为从基类继承的类,但未生成该基类 我了解

,当针对 DataContractSerializer 甚至 XmlSerializer 时,svcutil.exe/xsd.exe 支持的架构类型存在限制。我的问题有两个:

  1. 在处理较大的模块化 xsd 文件时,代码生成“问题”是否相当常见?有人成功地从 OAGIS 或 HR-XML 模式生成数据合同吗?
  2. 鉴于上述问题,是否有更好的方法来完成此任务,避免生成代码并使用具体对象?直接读取和编写 SOAP 消息是否更有意义,同时仍然利用 WCF 框架的其余部分?我知道我正在失去使用 .NET 对象的便利性,以及框架提供的(反)序列化;考虑到这些损失,将我的服务基于 WCF 是否仍然有利?使用 .NET 类型和纯 XML 之间是否存在某种“中间立场”?

非常感谢!

——萨莎·鲍罗丁 DFWHC.org

and thank you for reading.

I am implementing a WCF Service based on a predefined specification (HR-XML 3.0). As such, I am starting with the schema, and working my way back to code. There are a number of large Schema documents (which import yet more Schema documents) related to my implementation, provided by this specification.

I am able to generate code using xsd.exe, by supplying the "main" and "supporting" xsd files as arguments. But there are several issues, and I am wondering if this is the right approach.

  • there are litterally hundreds of classes - the code file is half a meg in size
  • duplicate classes (ex. Type, Type1 - which both represent the same type)
  • there are classes declared as inheriting from a base class, but that base class is not generated/defined

I understand that there are limitations to the types of Schema supported by svcutil.exe/xsd.exe when targeting the DataContractSerializer and even XmlSerializer. My question is two-fold:

  1. Are code generation "issues" fairly common when dealing with larger, modular xsd files? Has anyone had success with generating data contracts from OAGIS or HR-XML schema?
  2. Given the above issues, are there better approaches to this task, avoiding generating code and working with concrete objects? Does it make better sence to read and compose a SOAP message directly, while still taking advantage of the rest of the WCF framework? I understand that I am loosing the convenience of working with .NET objects, and the framekwork-provided (de)serialization; given these losses, would it still be advantageous to base my Service on WCF? Is there some "middle ground" between working with .NET types and pure XML?

Thank you very much!

-Sasha Borodin
DFWHC.org

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如梦亦如幻 2024-09-01 00:23:03

Sasha,如果您要使用代码生成,您可能永远不应该从模块化模式开始。当您针对模块化模式放置代码生成器时,您将为 HR-XML 库中的所有公共组件以及 OAGIS 中的大部分公共组件生成一个类。你不想要这个。 HR-XML 与独立模式一起分发,这是一个更好的起点。更好的起点是创建一个扁平化包 xsd,其中仅包含 WSDL 引入的类型。如果您使用几个独立模式,则生成的代码中至少会有一些重复。

Sasha, If you are going to use code generation, you likely should never start with the modular schemas. When you put a code generator against the modular schemas, you'll generate a class for all the common compoents in the HR-XML library and a good bit of the common components in OAGIS. You don't want this. HR-XML is distributed with standalone schemas, which are a better starting point. An even better starting point would be to create a flattened package xsd containing only the types brought in by the WSDL. If you use a couple standalone schemas, you are going to at least have some duplications among your generated code.

谁把谁当真 2024-09-01 00:23:03

好吧,您可以尝试执行以下操作:

  • 使用 Microsoft 的 xsd.exe 工具或 Xsd2Code 作为 Visual Studio 插件。

Visual Studio 中的 Xsd2Code http://i3.codeplex。 com/Project/Download/FileDownload.aspx?ProjectName=Xsd2Code&DownloadId=41336

  • 拥有 C# 类后,请清除任何不一致、重复的内容
  • 将所有内容打包到单独的类库程序集中

  • 现在,当从 WSDL 生成 WCF 服务时,可以使用 Visual Studio 中的添加服务引用或 svcutil.exe 工具,引用该程序集以及所有数据类。 WCF 应该再次跳过重新创建整个类集,并使用该数据集中可用的任何内容

这样,您也许能够控制这种混乱。

Well, you could try and do something like this:

  • convert your XSD to C# code separately, using something like the xsd.exe tool from Microsoft, or something like Xsd2Code as a Visual Studio Plugin.

Xsd2Code in Visual Studio http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=Xsd2Code&DownloadId=41336

  • once you have your C# classes, weed out any inconsistencies, duplications, and so forth
  • package everything up into a separate class library assembly

  • now, when generating your WCF service from the WSDL, either using Add Service Reference from Visual Studio or the svcutil.exe tool, reference that assembly with all the data classes. Doing so, WCF should skip re-creating the whole set of classes again, and use whatever is available in that data assembly

With this, you might be able to get this mess under control.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文