我尝试生成 WSDL,然后使用客户端手动在 WSDL 中找到的每个 XSD。该服务目前仅在我的本地主机上,尚未发布。
客户端出现以下错误:
The document was understood, but it could not be processed. The WSDL document contains links that could not be resolved. There was an error downloading 'http://localhost:xxxx/MyService.svc?xsd=xsd0'. Unable to connect to the remote server No connection could be made because the target machine actively refused it 127.0.0.1:xxxx
应该如何生成和共享服务 WSDL 和 XSD,以便它们可以开始编写客户端代码(无需访问服务 atm?
编辑 问题涉及到WSDL/XSD中的这些
WSDL
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost:xxxx/MyService.svc?xsd=xsd0"
namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://localhost:xxxx/MyService.svc?xsd=xsd1"
namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
<xsd:import schemaLocation="http://localhost:xxxx/MyService.svc?xsd=xsd2"
namespace="**MYNAMESPACE**"/>
</xsd:schema>
XSD
<xs:import schemaLocation="http://localhost:xxxx/MyService.svc?xsd=xsd1"
namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
编辑 2:
感谢 @The Indian Programmmer
,我能够生成一个代理类以使用此命令进行编程:
"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\svcutil.exe"-noconfig -namespace:*,SERVICE.INTERFACE.NAMESPACE -serializer:datacontractserializer https://My- PC/SvrLocation/MyService.svc?wsdl
(托管在本地 IIS 中)
最佳答案
首先通过运行您的服务浏览到您的 wsdl。
然后分别浏览到 WSDL 中的所有 xsd,并将它们另存为 xsd 文件。
用新的 xsd 相对路径更新你的 wsdl.. 只需用它的名字替换 xsd 的整个链接。
将 http://localhost:xxxx/MyService.svc?xsd=xsd0 替换为各自的文件名
<xsd:schema targetNamespace="namespace">
<xsd:import schemaLocation="Messages.xsd" namespace="namespace"/>
<xsd:import schemaLocation="DomainTypes.xsd" namespace="namespace"/>
<xsd:import schemaLocation="StreamBody.xsd" namespace="namespace"/>
</xsd:schema>
更新:如何生成代理文件
svcutil -noconfig -namespace:*,ServiceNameSpace -serializer:datacontractserializer "Service.wsdl" "DomainTypes.xsd" "Messages.xsd" "StreamBody.xsd"
所有文件都应该在同一个文件夹中。
关于c# - 您如何将 WCF WSDL 和 XSD 共享给尚未访问该服务的客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13154726/