You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 7.0导入WSDL抛出异常,SOAP UI连VPN可正常运行

解决.NET 7.0 ASP.NET Core Web API导入WSDL时的“这些成员不得被派生”错误

问题场景

在.NET 7.0的ASP.NET Core Web API项目中导入WSDL时触发以下错误,但连接公司VPN后用SOAP UI操作完全正常:

无法导入wsdl:port
详细信息:
错误源XPath://wsdl:definitions[@targetNamespace='urn:telmaServices']/wsdl:service[@name='telmaServices']/wsdl:port[@name='mbJIRServicePort']
无法导入wsdl:binding
详细信息:导入wsdl:binding依赖的wsdl:portType时出错。
wsdl:portType的XPath://wsdl:definitions[@targetNamespace='urn:telmaServices']/wsdl:portType[@name='mbJIRServicePortType']
错误源XPath://wsdl:definitions[@targetNamespace='urn:telmaServices']/wsdl:binding[@name='mbJIRServiceBinding']
无法导入wsdl:portType
详细信息:运行WSDL导入扩展时抛出异常:System.ServiceModel.Description.XmlSerializerMessageContractImporter
错误:这些成员不得被派生。
错误源XPath://wsdl:definitions[@targetNamespace='urn:telmaServices']/wsdl:portType[@name='mbJIRServicePortType']

解决步骤

  • 手动下载WSDL及关联XSD文件:通过SOAP UI或浏览器(连接VPN)访问WSDL地址,下载主WSDL文件,同时检查WSDL中引用的所有XSD文件,一并下载到本地同一目录。

  • 修改WSDL中的XSD引用路径:将WSDL里所有<xs:import>或<xs:include>标签的schemaLocation属性,从远程URL替换为本地XSD文件名(如./your-schema.xsd),确保所有依赖文件能被本地读取。

  • 用SvcUtil工具生成代理类:打开命令提示符,执行以下命令(替换路径和命名空间):

    svcutil.exe /language:C# /out:TelmaServiceProxy.cs /namespace:Your.Project.Namespace "C:\Local\Path\TelmaServices.wsdl" "C:\Local\Path\*.xsd"
    

    生成的TelmaServiceProxy.cs文件直接添加到项目中,即可通过代理类调用SOAP服务。

  • 切换序列化器类型:如果VS内置导入功能报错,可指定使用DataContractSerializer替代XmlSerializer,执行命令:

    svcutil.exe /serializer:DataContractSerializer /language:C# /out:TelmaServiceProxy.cs /namespace:Your.Project.Namespace "C:\Local\Path\TelmaServices.wsdl"
    
  • 调整WSDL/XSD的类型定义:若上述方法无效,检查WSDL对应的XSD文件,找到存在派生关系的复杂类型,移除不必要的<xs:extension>或<xs:restriction>节点,或者修改类型结构使其符合XmlSerializer的约束。

内容的提问来源于stack exchange,提问作者Salman Rafique

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 17:45:49