这是 this question 的后续内容.
按照建议by @Benjamin here ,我现在尝试为我的 wsdl 添加服务引用(而不是 Web 引用)。以下是相关 wsdl 的 url:
问题是 Visual Studio 生成了一个空代码文件:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.3603
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace test.ServiceReference1 {
}
当我尝试使用 svcutil 手动生成代码时,我得到以下信息:
C:\temp>svcutil https://eu.link.fiatauto.com/tsi/DDUWsAut.php?wsdl Microsoft (R) Service Model Metadata Tool [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152] Copyright (c) Microsoft Corporation. All rights reserved. Attempting to download metadata from 'https://eu.link.fiatauto.com/tsi/DDUWsAut. php?wsdl' using WS-Metadata Exchange or DISCO. Error: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.Se rviceModel.Description.XmlSerializerMessageContractImporter Error: The ' ' character, hexadecimal value 0x20, cannot be included in a name. Parameter name: name XPath to Error Source: //wsdl:definitions[@targetNamespace='urn:ddu']/wsdl:portT ype[@name='dduPortType'] Error: Cannot import wsdl:binding Detail: There was an error importing a wsdl:portType that the wsdl:binding is de pendent on. XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='urn:ddu']/wsdl:port Type[@name='dduPortType'] XPath to Error Source: //wsdl:definitions[@targetNamespace='urn:ddu']/wsdl:bindi ng[@name='dduBinding'] Error: Cannot import wsdl:port Detail: There was an error importing a wsdl:binding that the wsdl:port is depend ent on. XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='urn:ddu']/wsdl:bindi ng[@name='dduBinding'] XPath to Error Source: //wsdl:definitions[@targetNamespace='urn:ddu']/wsdl:servi ce[@name='ddu']/wsdl:port[@name='dduPort'] Generating files... Warning: No code was generated. If you were trying to generate a client, this could be because the metadata docu ments did not contain any valid contracts or services or because all contracts/services were discovered to exist in /reference assembl ies. Verify that you passed all the metadata documents to the tool. Warning: If you would like to generate data contracts from schemas make sure to use the /dataContractOnly option.
也许这也与尝试通过添加 Web 引用而不是服务引用来使用该服务时出现问题有关(请参阅我的 other question )?
我猜那个 wsdl 有问题,但我找不到到底是什么问题。
由于这是一个已经被其他人使用的第三方服务,我认为他们不会愿意更改他们的服务,那么有没有任何解决方法可以让 .NET 与该 Web 服务对话?
最佳答案
WSDL 中存在错误。 dduAbortRequest
消息的最后部分在名称末尾有一个空格。这可能只是一个错误。告诉他们这个问题,他们会修复它,他们会感谢您告诉他们。
WSDL 本身就是无效的。
<message name="dduAbortRequest">
<part name="Ticket" type="xsd:string"/>
<part name="ServiceId" type="xsd:string"/>
<part name="LoginId" type="xsd:string"/>
<part name="DocId " type="xsd:string"/> <!-- Should be "DocId" -->
</message>
关于wcf - 如何让 WCF 与此 Web 服务对话?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1954805/