从WSDL详细ServiceDescription /代理 [英] Detailed ServiceDescription / Proxy from WSDL

查看:339
本文介绍了从WSDL详细ServiceDescription /代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是类ServiceDescription / ServiceDescriptionImporter动态调用Web服务。我想挖成深一点的WSDL描述,并获得

I am using the classes ServiceDescription / ServiceDescriptionImporter to dynamically call web services. I'd like to dig a bit deeper into the WSDL description and get

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

1) Parameter info for each of the web methods

2)的实际类型/组合物的所有Web方法的每个参数(例如,如果一个WebMethod需要一些复杂类型作为参数,我需要知道原始/其他类型它是由为好,如果可能的话)

2) The actual types / composition each parameters of all the web methods (ie if a WebMethod takes some complex type as a parameter, I need to know the primitive / other types it is composed of as well, if possible)

下面是我对动态调用的代码:

Here is the code I have for the dynamical call:

    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只是不知道如何以编程方式解压。下面是一些类的Ive一直在探索:

I have been able to get as far as finding some basic info such as the method names, parameter info, but I need deeper analysis. For example I need access to essentially all the information that Wsdl.exe produces in proxy classes but I dont want to have to run Wsdl.exe, just discover the information dynamically. For every method I need to know what its return type is composed of, what its parameters are composed of, etc. I know its in the WSDL just not sure how to programmatically extract it. Here are some of the classes Ive been exploring:

ServiceDescription.Description 
ServiceDescription.Messages
ServiceDescription.Types

看来,很多人拿出空,但?

It seems that alot of them come up empty though?

在此先感谢。

EDITS

我有一个小进一步,这是XML模式( WSDL)我试图穿越:

I got a little further, this is the xml schema (WSDL) I am trying to traverse:

- <s:complexType name="Session">
- <s:complexContent mixed="false">
- <s:extension base="tns:EntityObject">
 - <s:sequence>
    <s:element minOccurs="0" maxOccurs="1" name="Name" type="s:string" /> 
    <s:element minOccurs="0" maxOccurs="1" name="Host" type="s:string" /> 
    <s:element minOccurs="0" maxOccurs="1" name="SessionType" type="s:string" /> 
    <s:element minOccurs="1" maxOccurs="1" name="LoginTime" type="s:dateTime" /> 
    <s:element minOccurs="1" maxOccurs="1" name="LogoutTime" type="s:dateTime" /> 
   </s:sequence>
  </s:extension>
 </s:complexContent>
   </s:complexType>



这是遍历代码:

And this is the code to traverse:

 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的复杂内容。产生在控制台下面的输出:

This gets me a little further, but not as far as getting the complexContent of the ComplexType. Produces the following output in the console:

会话会话

推荐答案

如果任何人有类似的问题,这里是我是如何做的:在XML模式

If anyone has a similar question, here is how I did it:

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<SimpleType> primitives = new List<SimpleType>(); 

                    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));
                    }
                }
            }
        } 

这篇关于从WSDL详细ServiceDescription /代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆