如何让 WCF 与此 Web 服务通信? [英] How can I make WCF talk to this web service?
问题描述
这是这个问题的后续.
按照@Benjamin 此处的建议,我现在正在尝试为我的 wsdl 添加服务引用(而不是 Web 引用).这是相关 wsdl 的网址:
<块引用>https://eu.link.fiatauto.com/tsi/DDUWsAut.php?wsdl
问题在于 Visual Studio 生成了一个空的代码文件:
//----------------------------------------------------------------//<自动生成>//此代码是由工具生成的.//运行时版本:2.0.50727.3603////对此文件的更改可能会导致不正确的行为,并且在以下情况下会丢失//重新生成代码.//</自动生成>//------------------------------------------------------------------------------命名空间 test.ServiceReference1 {}
当我尝试使用 svcutil 手动生成代码时,我得到以下信息:
<前>C:\temp>svcutil https://eu.link.fiatauto.com/tsi/DDUWsAut.php?wsdlMicrosoft (R) 服务模型元数据工具[Microsoft (R) Windows (R) 通信基础,版本 3.0.4506.2152]版权所有 (c) 微软公司.版权所有.尝试从https://eu.link.fiatauto.com/tsi/DDUWsAut"下载元数据.php?wsdl' 使用 WS-Metadata Exchange 或 DISCO.错误:无法导入 wsdl:portType详细信息:运行 WSDL 导入扩展时抛出异常:System.ServiceModel.Description.XmlSerializerMessageContractImporter错误:""字符,十六进制值 0x20,不能包含在名称中.参数名称:名称错误源的 XPath://wsdl:definitions[@targetNamespace='urn:ddu']/wsdl:portType[@name='dduPortType']错误:无法导入 wsdl:binding详细信息:导入 wsdl:portType 时出错,wsdl:binding 是 de悬而未决.wsdl:portType 的 XPath://wsdl:definitions[@targetNamespace='urn:ddu']/wsdl:port类型[@name='dduPortType']错误源的 XPath://wsdl:definitions[@targetNamespace='urn:ddu']/wsdl:binding[@name='dduBinding']错误:无法导入 wsdl:port详细信息:导入 wsdl:port 所依赖的 wsdl:binding 时出错继续.到 wsdl:binding 的 XPath://wsdl:definitions[@targetNamespace='urn:ddu']/wsdl:binding[@name='dduBinding']错误源的 XPath://wsdl:definitions[@targetNamespace='urn:ddu']/wsdl:service[@name='ddu']/wsdl:port[@name='dduPort']正在生成文件...警告:没有生成代码.如果您尝试生成客户端,这可能是因为元数据文档评论不包含任何有效的合同或服务或者因为发现所有合同/服务都存在于/reference 汇编中就是.验证您是否已将所有元数据文档传递给该工具.警告:如果您想从模式生成数据契约,请确保使用/dataContractOnly 选项.也许这也与通过添加网络引用而不是服务引用来尝试使用该服务时出现问题有关(请参阅我的 其他问题)?
我猜那个 wsdl 有问题,但我找不到确切的原因.
由于这是其他人已经在使用的第三方服务,我认为他们不会愿意改变他们的服务,那么是否有任何解决方法让 .NET 与该网络服务对话?
WSDL 中存在一个错误.dduAbortRequest
消息的最后一部分在名称末尾有一个空格.那可能只是一个错误.告诉他们,他们会修复它,他们会感谢你告诉他们.
WSDL 完全无效.
<part name="Ticket" type="xsd:string"/><part name="ServiceId" type="xsd:string"/><part name="LoginId" type="xsd:string"/><part name="DocId" type="xsd:string"/><!-- 应该是DocId"--></消息>
This is a follow up of this question.
As suggested by @Benjamin here, I am trying to add a service reference for my wsdl now (in stead of a web reference). Here is the url to the wsdl in question:
The problem is that Visual Studio generates an empty codefile:
//------------------------------------------------------------------------------
// <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 {
}
When I try to manually generate the code using svcutil, I get the following:
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.
Maybe this has also something to do with the fact that there are problems when trying to use the service by adding a web reference in stead of a service reference (see my other question)?
I guess there's something wrong with that wsdl, but I can't find what exactly.
As this is a third party service which is already used by others, I don't think they will be willing to change their service, so are there any workarounds to let .NET talk to that web service?
There's a bug in the WSDL. The final part in the dduAbortRequest
message has a space at the end of the name. That's probably just a bug. Tell them about it, and they'll fix it, and they'll thank you for telling them.
The WSDL is just plain invalid as-is.
<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 与此 Web 服务通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!