前辈展示了如何从本地文件导入,但您的 WSDL 引用一个或多个 XSD 的可能性很小,您将收到错误:
您必须下载所有引用的 XSD 文件,并将它们放在与引用的 WSDL 相同的目录中。然后您将不得不手动编辑 WSDL,并将schemaLocation更改为本地下载的文件。
前
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://gate.somesite.local:8084/Shop/SomeService.svc?xsd=xsd0" namespace="http://tempuri.org/" />
<xsd:import schemaLocation="http://gate.somesite.local:8084/Shop/SomeService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
<xsd:import schemaLocation="http://gate.somesite.local:8084/Shop/SomeService.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
</xsd:schema>
</wsdl:types>
后
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="tempuri.org.xsd" namespace="http://tempuri.org/" />
<xsd:import schemaLocation="schemas.microsoft.com.2003.10.Serialization.xsd" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
<xsd:import schemaLocation="schemas.microsoft.com.2003.10.Serialization.Arrays.xsd" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
</xsd:schema>
</wsdl:types>
请注意,那些下载的 XSD 文件也有可能引用 Web 地址。
像这样:
前
<xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/DaxServiceLibrary.Messages" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/DaxServiceLibrary.Messages" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation="http://gate.somesite.local:8084/Shop/DaxService.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
后
<xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/DaxServiceLibrary.Messages" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/DaxServiceLibrary.Messages" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation="schemas.microsoft.com.2003.10.Serialization.Arrays.xsd" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />