前辈们都说如何从本地文件导入,但你的WSDL文件很可能会引用一个或多个XSD文件,并且你会收到错误信息:
![WSDL引用错误](https://istack.dev59.com/NIxC9.webp)
你需要下载所有被引用的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文件可能会引用网络地址。
例如:
之前
<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" />