ServiceDescriptionImporter找不到web服务命名空间的定义
本文关键字:定义 命名空间 服务 找不到 web ServiceDescriptionImporter | 更新日期: 2023-09-27 18:24:51
我想知道是否有人知道如何解决我在使用ServiceDescriptionImporter
时遇到的问题。我正在使用CodeDOM动态生成web服务客户端代理,当web服务WSDL嵌入了类型模式时,以下代码工作正常,但是当WSDL包含导入时,下面的代码将生成无法找到类型定义的错误。我在web上做了一些研究,并添加了一些代码来将模式添加到导入程序中,但在为具有导入功能的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>
非常感谢
this(servicedescriptionimporter)不在.net的4.0框架中。所以你可以做的是更新到visualstudio2012(.net框架4.5最低要求)
帮助:http://msdn.microsoft.com/en-us/library/system.web.services.description.servicedescriptionimporter.aspx
我发现了一个有类似问题的帖子:
根WSDL 中的ServiceDescription Importer和Import指令
如果我注释掉对外部模式对象的检查并使用帖子中的代码:,这个问题似乎在这个WSDL上得到了解决
if (externalSchema is XmlSchemaImport)
我不知道为什么会这样,有人知道为什么吗?