尝试将 WSDL 导入 Visual Studio 2013 时出现循环引用错误 [英] Circular reference error while trying to import WSDL into Visual Studio 2013

查看:23
本文介绍了尝试将 WSDL 导入 Visual Studio 2013 时出现循环引用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Microsoft Visual 中导入描述 SIRI Web 服务的 WSDL 文件时Studio 2013,我收到一个错误:

When importing the WSDL file that describes a SIRI web service in Microsoft Visual Studio 2013, I get an error:

警告 5
自定义工具警告:无法导入操作 GetProductionTimetable 中名为 FaultName 的故障.不受支持的 WSDL,故障消息部分必须引用一个元素.此故障消息未引用元素.如果您对 WSDL 文档具有编辑权限,则可以通过使用元素"属性引用架构元素来解决问题.C:\path\to\TransportationDemo\TransportationDemo\Service References\ServiceReference\Reference.svcmap 1

Warning 5
Custom tool warning: Fault named FaultName in operation GetProductionTimetable cannot be imported. Unsupported WSDL, the fault message part must reference an element. This fault message does not reference an element. If you have edit access to the WSDL document, you can fix the problem by referencing a schema element using the 'element' attribute. C:\path\to\TransportationDemo\TransportationDemo\Service References\ServiceReference\Reference.svcmap 1

当使用 WSDL 的修改版,由以色列交通部创建,删减了很多方法,我又得到一个错误(其中包括其他错误):

When using a modified version of the WSDL, created by the Israeli Ministry of Transporation, which cuts out a lot of methods, I get another error (among other errors):

警告 5
自定义工具警告:无法导入 wsdl:portType
详细信息:运行 WSDL 导入扩展时引发异常:System.ServiceModel.Description.XmlSerializerMessageContractImporter
错误:来自 targetNamespace='http://www.siri.org.uk/siri<的组ServiceDeliveryBodyGroup"/a>' 的定义无效:循环组引用.
错误源的 XPath://wsdl:definitions[@targetNamespace='
http://new.webservice.namespace']/wsdl:portType[@name='SOAP-Port'] C:\path\to\TransportationDemo\TransportationDemo\Service References\ServiceReference1\Reference.svcmap 1

Warning 5
Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter
Error: Group 'ServiceDeliveryBodyGroup' from targetNamespace='http://www.siri.org.uk/siri' has invalid definition: Circular group reference.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://new.webservice.namespace']/wsdl:portType[@name='SOAP-Port'] C:\path\to\TransportationDemo\TransportationDemo\Service References\ServiceReference1\Reference.svcmap 1

似乎某些元素定义出现在多个 XSD 中.所以我尝试使用 svcutil.exe 手动创建代理代码.我逐个文件添加了依赖项所需的文件.起初,我可以选择添加哪个文件,siri.xsdsiri\siri_base-v1.3.xsd,因为它们都包含 的定义ServiceRequestStructure 元素.

It seems that some of the element definitions appear in more than one XSD. So I tried to use svcutil.exe to create the proxy code manually. I added file by file required for the dependencies. At first, I had a choice which file to add, siri.xsd or siri\siri_base-v1.3.xsd, as they both contain definitions of the ServiceRequestStructure element.

siri.xsd 路径中,我添加了所有依赖项,并以上述相同的循环引用结束.

In the siri.xsd path, I add all dependencies and end up with the same circular reference mentioned above.

siri\siri_base-v1.3.xsd 中,我实际上可以生成代码.我可以创建一个 SOAPPortClient 对象实例.我想调用它的 GetStopMonitoringServiceRequest 方法.但是为了能够输入必填字段,我需要一个 StopMonitoringRequestStructure 对象的实例.这是在 siri_stopMonitoring_service.xsd 文件中定义的,未包含在用于生成此代理的 XSD 列表中.当我do添加这个schema文件时,我也必须添加siri_stopTimetable_service.xsd(用于MonitoringRefStructure的定义),然后是循环依赖上面的错误信息再次出现.

In the siri\siri_base-v1.3.xsd I can actually get code generated. I can create a SOAPPortClient object instance. I would like to invoke the GetStopMonitoringServiceRequest method on it. But for me to be able to input required fields, I need an instance of a StopMonitoringRequestStructure object. This is defined in siri_stopMonitoring_service.xsd file, and was not included in the list of XSDs used to generate this proxy. When I do add this schema file, I have to add siri_stopTimetable_service.xsd too (for the definition of MonitoringRefStructure), and then the circular dependency error message from above appears again.

我在这里不知所措,希望在 WSDL 和 Visual Studio 或一般 SOAP 服务(或特别是这个服务)方面有更多经验的人帮助解决这个问题.

I'm at a loss here, and would appreciate help from someone with more experience in WSDL with Visual Studio, or just SOAP services in general (or this one in particular), to solve this issue.

请注意,SIRI 在两个单独的文件中呈现 Web 服务接口,siri_wsProducer.wsdlsiri_wsConsumer.wsdl.据我所知,我对与制作人"的交互感兴趣.

Please note that SIRI presents web service interfaces in two separate files, siri_wsProducer.wsdl and siri_wsConsumer.wsdl. I'm interested in interfacing with the "Producer", as far as I can understand.

这个问题是相关的——显然是由一位开发人员提出的,如果他参与这个讨论,我将非常感谢他,因为他似乎找到了一个解决方案:将 WSDL 导入 .NET 项目只会创建一个空命名空间

This question is related -- it's apparently by a fellow developer, who I would very much be thankful if he participates in this discussion, as he seems to have found a solution: Importing WSDL into a .NET project only creates an empty namespace

推荐答案

我对您的架构和 WSDL 进行了更多的尝试,并找到了您问题的答案,尽管您可能不喜欢它...

I have played a little more with your schemas and WSDL and found an answer to your issue, although you may not like it...

  • 取消选中重用类型复选框,因为这仅适用于重新导入定义的情况
  • 导入后,Visual Studio 将所有 XSD 置于服务引用下(单击显示隐藏文件").选择siri.xsd,它会告诉你它找不到两个包含.
  • 为了解决包含问题,我将包含 URI 更改为绝对 URI.这解决了 Visual Studio 无法找到文件然后正确复制它们的问题.
  • 现在重建时,它将在调试输出"窗口中显示正确的验证错误.最重要的是,它抱怨重新定义.我设法通过删除对 xml.xsd 的任何引用并简化使用它的几个地方(仅限 xml:lang)来解决此问题.我接下来要做的是将所有 XSD 直接放在根目录下,并修复 xsl:importxsl:include 中的所有引用以反映这一点.许多重定义错误现已消失
  • 它现在抱怨 xs:group 是循环的(以前是这样,但我希望其他警告不会出现):

  • There is no difference in unchecking the re-use types checkbox, because that only applies to situations where you re-import the definitions
  • After import, Visual Studio places all XSD's under the service reference (click "show hidden files"). Select siri.xsd and it will show you that it cannot locate two includes.
  • To fix the include-issue, I changed the include URI to an absolute URI. This resolved the issue with Visual Studio not being able to locate the files and it then copies them properly.
  • When now rebuilding, it will show in the Debug Output window the proper validation errors. Most importantly, it complains about redefinitions. I managed to resolve this by removing any reference to xml.xsd and simplifying the few places where it was used (xml:lang only). Next thing I did was to place all XSD's directly under the root and fixed all references in xsl:import and xsl:include to reflect this. Many redefinition errors now disappeared
  • It now complains about an xs:group being circular (it did so before, but I wanted other warnings to be out of the way):

Microsoft.ServiceModel.targets(113,5):错误:来自 targetNamespace=' 的ServiceDeliveryBodyGroup"组http://www.siri.org.uk/siri' 的定义无效:循环组引用.

Microsoft.ServiceModel.targets(113,5): error : Group 'ServiceDeliveryBodyGroup' from targetNamespace='http://www.siri.org.uk/siri' has invalid definition: Circular group reference.

这是一个棘手的问题,因为我没有设法追踪为什么它被认为是循环的,但如果是,这在 XSD 中是允许的.它被导入了两次,但这似乎不是原因,我认为这是故意的.

This is a tricky one, because I didn't manage to track why it is considered circular, but if it is, this is allowed in XSD. It gets imported twice, but that does not seem to be the cause, I think this is deliberate.

进一步搜索后,似乎是微软的xsd.exe,与wsdl.exesvcutil使用的代码类似并添加服务引用,已确认此限制了他们的 XSD 到对象映射工具.

After some further searches, it appears that Microsoft's xsd.exe, which is similar to the code used by wsdl.exe, svcutil and add a service reference, has acknowledged this to be a limitation of their XSD-to-object mapping tools.

我认为你最好的办法是把那个小组变成非圆形.之后,它应该接受模式为有效并继续.进口商抱怨 wsdl:portType 的事实并没有为您指明正确的方向.它抱怨说,因为它无法映射所有类型,导致根本没有映射任何类型,之后 wsdl:portType 也是未知的,因此错误.

I think your best bet is to take that group and make it non-circular. After that, it should accept the schemas as valid and proceed. The fact that the importer complains about wsdl:portType does not point you in the right direction. It complains about that, because it fails to map all types, which results in mapping no types at all, after which also wsdl:portType is unknown, hence the error.

修复 ServiceDeliveryBodyGroup 类型后,上述其他步骤很可能会过时.其他错误实际上是警告,我相信 Microsoft 基本上会忽略此类重新定义,并将正常"进行.

It is very well possible that the other steps outlined above become obsolete after you fix the ServiceDeliveryBodyGroup type. The other errors were actually warnings, and I believe that Microsoft essentially ignores such redefinitions anyway and will proceed "normally".

这篇关于尝试将 WSDL 导入 Visual Studio 2013 时出现循环引用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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