ServiceDescriptionImporter 找不到 Web 服务命名空间的定义

发布于 2025-01-06 00:51:37 字数 3344 浏览 1 评论 0原文

我想知道是否有人知道如何解决我在使用 ServiceDescriptionImporter 时遇到的问题。我正在使用 CodeDOM 动态生成 W​​eb 服务客户端代理,当 Web 服务 WSDL 嵌入了类型架构时,以下代码可以正常工作,但是当 WSDL 包含导入时,以下代码将生成无法找到类型定义的错误。我在网上做了一些研究,并添加了一些代码来将架构添加到导入器,但在使用导入为 WSDL 创建代理时仍然收到错误。

Stream stream = client.OpenRead(wsURL);

ServiceDescription description = ServiceDescription.Read(stream);

ServiceDescriptionImporter importer = new ServiceDescriptionImporter();

importer.ProtocolName = "Soap12"; // Use SOAP 1.2.

importer.AddServiceDescription(description, null, null);

// Add any imported files
foreach (System.Xml.Schema.XmlSchema wsdlSchema in description.Types.Schemas)
{
    foreach (System.Xml.Schema.XmlSchemaObject externalSchema in wsdlSchema.Includes)
    {
        if (externalSchema is System.Xml.Schema.XmlSchemaImport)
        {
            Uri baseUri = new Uri(wsURL);
            Uri schemaUri = new Uri(baseUri, ((System.Xml.Schema.XmlSchemaExternal)externalSchema).SchemaLocation);
            stream = client.OpenRead(schemaUri);
            System.Xml.Schema.XmlSchema schema = System.Xml.Schema.XmlSchema.Read(stream, null);
            importer.Schemas.Add(schema);
        }
    }
}

importer.Style = ServiceDescriptionImportStyle.Client;

importer.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.GenerateProperties;

CodeNamespace nmspace = new CodeNamespace();
CodeCompileUnit unit1 = new CodeCompileUnit();

unit1.Namespaces.Add(nmspace);

// This is generating the error:
ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit1);

收到的错误:

找不到“xyz”的定义。缺少命名空间“xyz”的服务描述。 参数名称:名称

WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.ibm.com/maximo" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.ibm.com/maximo" xmlns:i0="http://www.ibm.com/maximo/wsdl/UWMFO_UWMFO_BB_Interface" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:s="http://www.w3.org/2001/XMLSchema">
 <wsdl:import location="http://localhost/MaximoWS/MessageService.asmx?wsdl=wsdl1" namespace="http://www.ibm.com/maximo/wsdl/UWMFO_UWMFO_BB_Interface"/>
 <wsdl:types>
  <s:schema targetNamespace="http://www.ibm.com/maximo">
   <s:include schemaLocation="http://localhost/MaximoWS/MessageService.asmx?schema=schema1"/>
  </s:schema>
 </wsdl:types>
 <wsdl:service name="MessageService">
  <wsdl:port name="UWMFO_UWMFO_BB_InterfaceSOAP12Binding" binding="i0:UWMFO_UWMFO_BB_InterfaceSOAP12Binding">
   <soap:address location="http://localhost/MaximoWS/MessageService.asmx"/> 
  </wsdl:port>
  <wsdl:port name="UWMFO_UWMFO_BB_InterfaceSOAP12Binding1" binding="i0:UWMFO_UWMFO_BB_InterfaceSOAP12Binding1">
   <soap12:address location="http://localhost/MaximoWS/MessageService.asmx"/> 
  </wsdl:port>
 </wsdl:service>
</wsdl:definitions>

非常感谢

I'm wondering if anyone knows how to overcome an issue I'm getting when using ServiceDescriptionImporter. I am generating web service client proxy dynamically using CodeDOM, when the web service WSDL has type schema embedded the following code works fine, however when the WSDL contains an import the following code will generate an error on not being able to find the type definition. I did some research on the web and added some code to add the schema to the importer, but I still receive error when creating proxies for WSDLs with import.

Stream stream = client.OpenRead(wsURL);

ServiceDescription description = ServiceDescription.Read(stream);

ServiceDescriptionImporter importer = new ServiceDescriptionImporter();

importer.ProtocolName = "Soap12"; // Use SOAP 1.2.

importer.AddServiceDescription(description, null, null);

// Add any imported files
foreach (System.Xml.Schema.XmlSchema wsdlSchema in description.Types.Schemas)
{
    foreach (System.Xml.Schema.XmlSchemaObject externalSchema in wsdlSchema.Includes)
    {
        if (externalSchema is System.Xml.Schema.XmlSchemaImport)
        {
            Uri baseUri = new Uri(wsURL);
            Uri schemaUri = new Uri(baseUri, ((System.Xml.Schema.XmlSchemaExternal)externalSchema).SchemaLocation);
            stream = client.OpenRead(schemaUri);
            System.Xml.Schema.XmlSchema schema = System.Xml.Schema.XmlSchema.Read(stream, null);
            importer.Schemas.Add(schema);
        }
    }
}

importer.Style = ServiceDescriptionImportStyle.Client;

importer.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.GenerateProperties;

CodeNamespace nmspace = new CodeNamespace();
CodeCompileUnit unit1 = new CodeCompileUnit();

unit1.Namespaces.Add(nmspace);

// This is generating the error:
ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit1);

The error received:

Cannot find definition for 'xyz'. Service Description with namespace 'xyz' is missing.
Parameter name: name

WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.ibm.com/maximo" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.ibm.com/maximo" xmlns:i0="http://www.ibm.com/maximo/wsdl/UWMFO_UWMFO_BB_Interface" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:s="http://www.w3.org/2001/XMLSchema">
 <wsdl:import location="http://localhost/MaximoWS/MessageService.asmx?wsdl=wsdl1" namespace="http://www.ibm.com/maximo/wsdl/UWMFO_UWMFO_BB_Interface"/>
 <wsdl:types>
  <s:schema targetNamespace="http://www.ibm.com/maximo">
   <s:include schemaLocation="http://localhost/MaximoWS/MessageService.asmx?schema=schema1"/>
  </s:schema>
 </wsdl:types>
 <wsdl:service name="MessageService">
  <wsdl:port name="UWMFO_UWMFO_BB_InterfaceSOAP12Binding" binding="i0:UWMFO_UWMFO_BB_InterfaceSOAP12Binding">
   <soap:address location="http://localhost/MaximoWS/MessageService.asmx"/> 
  </wsdl:port>
  <wsdl:port name="UWMFO_UWMFO_BB_InterfaceSOAP12Binding1" binding="i0:UWMFO_UWMFO_BB_InterfaceSOAP12Binding1">
   <soap12:address location="http://localhost/MaximoWS/MessageService.asmx"/> 
  </wsdl:port>
 </wsdl:service>
</wsdl:definitions>

Thanks very much

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白衬杉格子梦 2025-01-13 00:51:37

这个(servicedescriptionimporter)不在.net 4.0框架中。
所以你可以做的是更新到 Visual Studio 2012(.net Framework 4.5 的最低要求)。

帮助 ::
http://msdn.microsoft.com/en -us/library/system.web.services.description.servicedescriptionimporter.aspx

this (servicedescriptionimporter) is not in 4.0 framework of .net.
so you can do is update to visual studio 2012( minimum required for .net framework 4.5).

help ::
http://msdn.microsoft.com/en-us/library/system.web.services.description.servicedescriptionimporter.aspx

那请放手 2025-01-13 00:51:37

我发现一个帖子有类似的问题:

根 WSDL 中的 ServiceDescription 导入器和导入指令

如果我注释掉该检查,此 WSDL 上的问题似乎已得到解决在外部模式对象上并使用帖子中的代码:

if (externalSchema is XmlSchemaImport)

我不知道为什么这个有效,有人知道为什么吗?

I found a post which had a similar problem:

ServiceDescription Importer and Import directives in the root WSDL

The issue seems to be resolved on this WSDL if I comment out the check on the external schema object and uses the code in the post:

if (externalSchema is XmlSchemaImport)

I don't know why this work, does anyone know why?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文