.Net Core 3.1 导入 WSDL 错误 - 如何解决?

.Net Core 3.1 importing WSDL Errors - How to work around?

我正在尝试将一些服务器代码从 .Net 4.7 迁移到 .Net Core 3.1,以便我们可以 运行 在 Linux 主机上。

有两个连接的服务使用 SOAP。一个已移植且更改为零,但其他在使用 WSDL 文件导入时出现错误:

http://uat.risc.enexusrental.co.uk/SOAP/IndividualService.php?wsdl

我不是 SOAP 专家,只使用过导入 WSDL 文件生成的代码,所以这些错误对我来说意义不大。

Cannot import wsdl:port Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on. XPath to wsdl:binding: wsdl:definitions[@targetNamespace='http://uat.risc.enexusrental.co.uk']/wsdl:binding[@name='IndividualServiceHttpPost'] XPath to Error Source: //wsdl:definitions[@targetNamespace='http://uat.risc.enexusrental.co.uk']/wsdl:service[@name='IndividualService']/wsdl:port[@name='IndividualServiceHttpPost'] Cannot import wsdl:binding Detail: The required WSDL extension element 'binding' from namespace 'http://schemas.xmlsoap.org/wsdl/http/' was not handled. XPath to Error Source: //wsdl:definitions[@targetNamespace='http://uat.risc.enexusrental.co.uk']/wsdl:binding[@name='IndividualServiceHttpPost'] Cannot import wsdl:port Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on. XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://uat.risc.enexusrental.co.uk']/wsdl:binding[@name='IndividualServiceHttpGet'] XPath to Error Source: //wsdl:definitions[@targetNamespace='http://uat.risc.enexusrental.co.uk']/wsdl:service[@name='IndividualService']/wsdl:port[@name='IndividualServiceHttpGet'] Cannot import wsdl:binding Detail: The required WSDL extension element 'binding' from namespace 'http://schemas.xmlsoap.org/wsdl/http/' was not handled. XPath to Error Source: //wsdl:definitions[@targetNamespace='http://uat.risc.enexusrental.co.uk']/wsdl:binding[@name='IndividualServiceHttpGet']

为了简化调试,我创建了简单的命令行应用程序,一个用于 .Net 4.7,另一个用于 Core 3.1。

.Net 4.7 的导入工作非常完美,我可以调用该服务(如预期的那样)。

为 Core 3.1 导入会出现上述错误,并且在调用客户端初始化时会出现 returns 错误:

Client.Channel = 'Client.Channel' threw an exception of type 'System.ServiceModel.CommunicationObjectFaultedException'

我在使用 svcutil.exe 手动导入时遇到同样的错误。

谷歌搜索 3 天后,我没有继续深入,因为每个问题似乎都不一样,none 的解决方案有效。

是否有人愿意解释这些错误的实际含义(我不是 SOAP 专家),如果可能的话,我需要做些什么来解决这些错误?

将 WSDL 下载到文件并通过删除相应的 wsdl:bindingwsdl:port 元素手动删除不受支持的 GET 和 POST 绑定。然后,您可以使用工具(dotnet-svcutil 或 Visual Studio / IDE)生成客户端代码(服务参考)。

    --- a/service.wsdl
    +++ b/service.wsdl
    @@ -286,37 +286,6 @@
           </wsdl:output>
         </wsdl:operation>
       </wsdl:binding>
    -  <wsdl:binding name="IndividualServiceHttpGet" type="tns:IndividualServiceHttpGet">
    -    <http:binding verb="GET" />
    -    <wsdl:operation name="SearchByLastNameAndDateOfBirth">
    -      <http:operation location="/SearchByLastNameAndDateOfBirth" />
    -      <wsdl:input>
    -        <http:urlEncoded />
    -      </wsdl:input>
    -      <wsdl:output>
    -        <mime:mimeXml part="Body" />
    -      </wsdl:output>
    -    </wsdl:operation>
    -    <wsdl:operation name="SearchByDrivingLicenceNumber">
    -      <http:operation location="/SearchByDrivingLicenceNumber" />
    -      <wsdl:input>
    -        <http:urlEncoded />
    -      </wsdl:input>
    -      <wsdl:output>
    -        <mime:mimeXml part="Body" />
    -      </wsdl:output>
    -    </wsdl:operation>
    -    <wsdl:operation name="Get">
    -      <http:operation location="/Get" />
    -      <wsdl:input>
    -        <http:urlEncoded />
    -      </wsdl:input>
    -      <wsdl:output>
    -        <mime:mimeXml part="Body" />
    -      </wsdl:output>
    -    </wsdl:operation>
    -  </wsdl:binding>
    -  <wsdl:binding name="IndividualServiceHttpPost" type="tns:IndividualServiceHttpPost">
         <http:binding verb="POST" />
         <wsdl:operation name="SearchByLastNameAndDateOfBirth">
           <http:operation location="/SearchByLastNameAndDateOfBirth" />
    @@ -354,11 +323,5 @@
         <wsdl:port name="IndividualServiceSoap12" binding="tns:IndividualServiceSoap12">
           <soap12:address location="http://uat.risc.enexusrental.co.uk/SOAP/IndividualService.php" />
         </wsdl:port>
    -    <wsdl:port name="IndividualServiceHttpGet" binding="tns:IndividualServiceHttpGet">
    -      <http:address location="http://uat.risc.enexusrental.co.uk/SOAP/IndividualService.php" />
    -    </wsdl:port>
    -    <wsdl:port name="IndividualServiceHttpPost" binding="tns:IndividualServiceHttpPost">
    -      <http:address location="http://uat.risc.enexusrental.co.uk/SOAP/IndividualService.php" />
    -    </wsdl:port>
       </wsdl:service>
     </wsdl:definitions>

之后我遇到了类似的问题,我使用“svcutil”并使用以下命令创建了一个批处理文件

"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\svcutil.exe" <your service address/url like http://localhost:*****/***/**/***** >  /o:"<name of class file to be created>.cs" /r:"..\..\<Any reference assembly if any otherwise leave this>" /n:*,<targetNamespace>  /ct:<collectionType:<type> like System.Collections.Generic.List`1>

有关 svcutil 的更多信息,请转到 VS 的开发命令和 运行 命令:svcutil/?