来自WSDL的详细ServiceDescription / Proxy

我使用ServiceDescription / ServiceDescriptionImporter类来动态调用Web服务。 我想更深入地了解WSDL描述并得到

1)每个Web方法的参数信息

2)所有Web方法的每个参数的实际类型/组成(即,如果WebMethod将某些复杂类型作为参数,我需要知道它由原型/其他类型组成,如果可能的话)

这是动态调用的代码:

public static object CallWebService(string webServiceAsmx, string serviceName, string methodName, object[] args = null) { WebClient client = new WebClient(); Stream stream = client.OpenRead(webServiceAsmx + "?wsdl"); ServiceDescription description = ServiceDescription.Read(stream); ServiceDescriptionImporter importer = new ServiceDescriptionImporter(); importer.ProtocolName = "Soap12"; importer.AddServiceDescription(description, null, null); importer.Style = ServiceDescriptionImportStyle.Client; importer.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties; 

我已经能够找到一些基本信息,如方法名称,参数信息,但我需要更深入的分析。 例如,我需要访问Wsdl.exe在代理类中生成的基本上所有信息,但我不想运行Wsdl.exe,只是动态发现信息。 对于每个方法,我需要知道它的返回类型是由什么组成的,它的参数是由什么组成的等等。我知道它在WSDL中只是不确定如何以编程方式提取它。 以下是我一直在探索的一些课程:

 ServiceDescription.Description ServiceDescription.Messages ServiceDescription.Types 

看来很多它们都空了?

提前致谢。

EDITS

我进一步了,这是我试图遍历的xml架构(WSDL):

 -  -  -  -           

这是遍历的代码:

  foreach (System.Xml.Schema.XmlSchemaComplexType item in xmlSchema.SchemaTypes.Values) { if (item != null) { System.Xml.Schema.XmlSchemaParticle particle = item.Particle; System.Xml.Schema.XmlSchemaSequence sequence = particle as System.Xml.Schema.XmlSchemaSequence; if (sequence != null) { foreach (System.Xml.Schema.XmlSchemaElement childElement in sequence.Items) { string name = childElement.Name; string type = childElement.SchemaTypeName.Name; Console.WriteLine(name + " " + type); } } } 

这让我更进一步,但没有获得ComplexType的complexContent。 在控制台中生成以下输出:

会话会话

如果有人有类似的问题,我就是这样做的:

 foreach (System.Xml.Schema.XmlSchemaComplexType item in xmlSchema.SchemaTypes.Values) { ComplexType cType = new ComplexType(item.Name); System.Xml.Schema.XmlSchemaContentModel model = item.ContentModel; System.Xml.Schema.XmlSchemaComplexContent complex = model as System.Xml.Schema.XmlSchemaComplexContent; if (complex != null) { System.Xml.Schema.XmlSchemaComplexContentExtension extension = complex.Content as System.Xml.Schema.XmlSchemaComplexContentExtension; System.Xml.Schema.XmlSchemaParticle particle = extension.Particle; System.Xml.Schema.XmlSchemaSequence sequence = particle as System.Xml.Schema.XmlSchemaSequence; if (sequence != null) { List primitives = new List(); foreach (System.Xml.Schema.XmlSchemaElement childElement in sequence.Items) { string name = childElement.Name; string type = childElement.SchemaTypeName.Name; cType.Primitives.Add(new SimpleType(name, type)); } if (cType.Name == parameter.Type || "ArrayOf" + cType.Name == parameter.Type) { descriptions.Add(new ComplexParameter(cType, item.Name)); } } } } 

这看起来与您所做的非常相似WebServiceInfo它返回带有info的自定义对象。 (如果我理解你的问题和博客足够好)