svcutil 无法从 wsdl 文件生成代码
Posted
技术标签:
【中文标题】svcutil 无法从 wsdl 文件生成代码【英文标题】:svcutil fails to generate code from wsdl file 【发布时间】:2020-09-22 01:07:04 【问题描述】:我工作的一家公司正在开发他们自己的内部解决方案,需要让他们的客户能够继续使用各种版本的 SOAP 服务。
使用svcutil /sc *.wsdl *.xsd
时出现错误;
svcutil /sc *.wsdl *.xsd
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.8.3928.0]
Copyright (c) Microsoft Corporation. All rights reserved.
Error: All parts of message in operation must either contain type or element.
Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter
Error: Referenced type 'http://schemas.xmlsoap.org/soap/encoding/:Array' is only valid for encoded SOAP.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://www.xxxxxxxxxx.uk/myapp/']/wsdl:portType[@name='ProposalPortType']
Error: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://www.xxxxxxxxxx.uk/myapp/']/wsdl:portType[@name='ProposalPortType']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://www.xxxxxxxxxx.uk/myapp/']/wsdl:binding[@name='ProposalBinding']
Error: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://www.xxxxxxxxxx.uk/myapp/']/wsdl:binding[@name='ProposalBinding']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://www.xxxxxxxxxx.uk/myapp/']/wsdl:service[@name='Proposal-service']/wsdl:port[@name='ProposalPort']
Generating files...
Warning: No code was generated.
如果我从消息中删除它
<part name="attachment" type="oneapp:ArrayOfBinary"/>
完整的消息
<message name="ProposalOutput">
<!-- This is the main message content which describes the Proposal -->
<part name="out" element="xsd1:Proposal"/>
<!-- There may be zero to many attachment parts -->
<!--<part name="attachment" type="oneapp:ArrayOfBinary"/>-->
</message>`
然后生成代码,但是通过显式删除这些项目,我不完全确定我删除了什么或它将对需要创建的新服务产生什么影响。
我的问题是,为什么这两个项目会导致代码生成失败,我该如何解决?
【问题讨论】:
【参考方案1】:你的 WSDL 文档是关于 Java WebService 的吗?如果是,使用的 svcutil 命令应该如下所示:
svcutil *.wsdl *.xsd /language:C#
根据您提供的信息,我发现您没有添加语言,可能会导致这个问题。
关于svcutil的更多信息,请参考以下链接:
https://docs.microsoft.com/en-us/dotnet/framework/wcf/servicemodel-metadata-utility-tool-svcutil-exe
【讨论】:
对不起,我直到现在才看到这个回复。我怀疑这是用 Java 创建的,但是我们现在需要在 .net 中复制它 这不起作用,因为得到了这个回复svcutil *.wsdl *.xsd /language:Java Microsoft (R) Service Model Metadata Tool [Microsoft (R) Windows (R) Communication Foundation, Version 4.8.3928.0] Copyright (c) Microsoft Corporation. All rights reserved. Error: The value 'Java' passed to the /language argument does not represent a defined language and it could not be loaded as a fully qualified CLR type. If you would like more help, type "svcutil /?"
您可以尝试将语言更改为 C#。
可以尝试在VS中添加服务引用直接生成代理类,或者使用WSDL.exe。
通过VS试过,但是我没有试过WSDL.exe,我试试吧以上是关于svcutil 无法从 wsdl 文件生成代码的主要内容,如果未能解决你的问题,请参考以下文章
在 SvcUtil 和 WSDL 代码生成期间抓取 KnownType 属性
为啥 svcutil.exe 的 /reference 选项不起作用?