2012-02-16 73 views
0

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

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> 

非常感谢

+0

你有失败的WSDL的例子吗? – svick 2012-02-16 01:06:15

+0

嗨svick,以下是wsdl: – JerryH 2012-02-16 01:20:52

+0

您可以编辑问题并在其中添加WSDL(或链接)。 – svick 2012-02-16 01:32:38

回答

3

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

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

+1

PS我知道,并通过链接有本: http://social.msdn.microsoft.com/Forums/vstudio/en-US/39138d08-aa08-4c0c-9a58-0eb81a672f54/adding-a-web-reference -dynamically-在运行时 – Sid 2013-08-20 11:03:27

相关问题