none
portType is coming as null in wsdl parsing RRS feed

  • Question

  • I am in the middle implementation small programme of WSDL parser. But I am getting ptobject is coming NULL. This is happening with the wsdl mentioned in the programme. I dont think WSDL is wrong because if give the same WSDL to SOAP UI it is parsing successfully.

    Could you please help in uunderstanding the root cause of the problem ?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using System.Xml.Schema;
    using System.Xml.Serialization;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Net;
    using System.Reflection;
    using System.Web.Services.Description;
    namespace ConsoleApplication14
    {
        class XmlSchemaReadWriteExample
        {

            static void Main()
            {
               
                XmlTextReader myReader = new XmlTextReader("https://domainws.ficora.fi/fiDomain/DomainNameWS_FicoraDomainNameWS.svc?wsdl");

                if (ServiceDescription.CanRead(myReader))
                {
                    ServiceDescription myDescription =
                       ServiceDescription.Read(myReader);
                    Dictionary<string, Service> Services;
                    foreach (Service srv in myDescription.Services)
                    {

                        Services = new Dictionary<string, Service>();
                        Services.Add(srv.Name, srv);
                        foreach (Port p in srv.Ports)
                        {
                            Binding b = myDescription.Bindings[p.Binding.Name];
                            foreach (Object e in b.Extensions)
                            {
                                if (e is Soap12Binding
                                    || e is SoapBinding)
                                {
                                    PortType ptobject = myDescription.PortTypes[b.Type.Name];
                                   
                                }
                            }
                        }
                    }
                }
            }
        }
    }
                
               

    Tuesday, May 10, 2016 5:46 PM

Answers

  • Hello,

    In order to import port Types from another WSDL, first we can use the ServiceDescription.Imports to get the location of the another WSDL in your WSDL, after that we can get the port Types from the another WSDL by using the ServiceDescription.PortTypes, I have created the following example for you, please try to check it:

    static void Main(string[] args)
            {
                string wsdlUrl = "https://domainws.ficora.fi/fiDomain/DomainNameWS_FicoraDomainNameWS.svc?wsdl"; //"http://localhost/MessageWithWindows/Service.svc?wsdl"
                XmlTextReader myReader = new XmlTextReader(wsdlUrl);
                if (ServiceDescription.CanRead(myReader))
                {
                    ServiceDescription myDescription = ServiceDescription.Read(myReader);
    
                    foreach (Import im in myDescription.Imports)
                    {
                        string wsdl2 = im.Location;
                        XmlTextReader myReader2 = new XmlTextReader(wsdl2);
                        if (ServiceDescription.CanRead(myReader2))
                        {
                            ServiceDescription subDescription = ServiceDescription.Read(myReader2);
    
                            foreach (PortType pt in subDescription.PortTypes)
                            {
                                foreach (Operation op in pt.Operations)
                                {
                                    Console.WriteLine("{0}", op.Name);
                                    Console.ReadLine();
                                }
                            }
                        }
                    }
    
                }
    
            }

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Friday, May 13, 2016 9:21 AM
    Moderator
  • >>Is there any way to add import section to my description object?

    Do you mean that you want to retrieve the PortType object from the variable named subDescription and assign them to variable named myDescription?  If it’s the case, please refer to the following code:

    string wsdlUrl = "https://domainws.ficora.fi/fiDomain/DomainNameWS_FicoraDomainNameWS.svc?wsdl"; //"http://localhost/MessageWithWindows/Service.svc?wsdl"
                XmlTextReader myReader = new XmlTextReader(wsdlUrl);
                if (ServiceDescription.CanRead(myReader))
                {
                    ServiceDescription myDescription = ServiceDescription.Read(myReader);
    
                    //ImportCollection ic = myDescription.Imports;
                    foreach (Import im in myDescription.Imports)
                    {
                        string wsdl2 = im.Location;
                        XmlTextReader myReader2 = new XmlTextReader(wsdl2);
                        if (ServiceDescription.CanRead(myReader2))
                        {
                            ServiceDescription subDescription = ServiceDescription.Read(myReader2);
    
                            foreach(PortType pt in subDescription.PortTypes)
                            {
                                myDescription.PortTypes.Add(pt);
                            }
                        }
                    }
    
                    foreach (PortType pt in myDescription.PortTypes)
                    {
                        foreach (Operation op in pt.Operations)
                        {
                            Console.WriteLine("{0}", op.Name);
                        }
                    }
                }
    


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 20, 2016 1:28 AM

All replies

  • Hi all,

    Lets suppose i have two schema A and B.                                          

    In A i have just types in B i have operations defined. A is the main wsdl file where i start parsing ,how can 
    i get Operations information using c#.(i have imported B from A)

    Thanks in advance.



    vishnu

    Sunday, May 8, 2016 8:01 AM
  • Hello,

    Could you please describe more about your question? It will be better if you can show us the detailed information about Schema A and Schema B in your scenario.

    Thanks for your understanding.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 9, 2016 10:26 AM
    Moderator
  • Lets take example as below WSDL

    https://domainws.ficora.fi/fidomain/DomainNameWS_FicoraDomainNameWS.svc?wsdl-- (A)

    in the above WSDL he is importing another WSDL as:

    <wsdl:import namespace="http://domainws.ficora.fi.operations"location="https://domainws.ficora.fi/fiDomain/DomainNameWS_FicoraDomainNameWS.svc?wsdl=wsdl0"/>

    basically he has defined complete <operation> section in that particular WSDL.

    i am parsing the above WSDL using C#.and I have created a servicedescription object for A(https://domainws.ficora.fi/fidomain/DomainNameWS_FicoraDomainNameWS.svc?wsdl).

    How can i get the Operation information That are declared in another schema which is imported in current schema.


    vishnu

    Monday, May 9, 2016 10:57 AM
  • Hello,

    I can reproduce this issue in my side. I will work on this issue, once there is any update, I will post it here.

    Thanks for your understanding.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, May 11, 2016 10:57 AM
    Moderator
  • Hi Peng,

    Happy that issue was reproduced in local enironment of yours. I cant ask you to expidite the solution but I want let you know that I am eager for solution of this problem :). It is blocker to my component.

    Thanks for understanding

    Bheem,

    Wednesday, May 11, 2016 11:04 AM
  • Peng,

    The WSDL mentioned in this example has import section which imports port Types from another WSDL. myDescriptionobject does not another wsdl. How to import the definitions which are mentioned in the other WSDLs . Hope this information may help you 

    Thursday, May 12, 2016 9:13 AM
  • Schema A and Schema B are two WSDLs. All the WSDL are xml-based. You can use the XmlTextReader or XmlDocument to read the all the XML-based information. Of course you can read the Operation information from others schame.
    Thursday, May 12, 2016 2:53 PM
  • Hello,

    In order to import port Types from another WSDL, first we can use the ServiceDescription.Imports to get the location of the another WSDL in your WSDL, after that we can get the port Types from the another WSDL by using the ServiceDescription.PortTypes, I have created the following example for you, please try to check it:

    static void Main(string[] args)
            {
                string wsdlUrl = "https://domainws.ficora.fi/fiDomain/DomainNameWS_FicoraDomainNameWS.svc?wsdl"; //"http://localhost/MessageWithWindows/Service.svc?wsdl"
                XmlTextReader myReader = new XmlTextReader(wsdlUrl);
                if (ServiceDescription.CanRead(myReader))
                {
                    ServiceDescription myDescription = ServiceDescription.Read(myReader);
    
                    foreach (Import im in myDescription.Imports)
                    {
                        string wsdl2 = im.Location;
                        XmlTextReader myReader2 = new XmlTextReader(wsdl2);
                        if (ServiceDescription.CanRead(myReader2))
                        {
                            ServiceDescription subDescription = ServiceDescription.Read(myReader2);
    
                            foreach (PortType pt in subDescription.PortTypes)
                            {
                                foreach (Operation op in pt.Operations)
                                {
                                    Console.WriteLine("{0}", op.Name);
                                    Console.ReadLine();
                                }
                            }
                        }
                    }
    
                }
    
            }

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Friday, May 13, 2016 9:21 AM
    Moderator
  • Hi Peng,

    Thanks for your reply. Can we collect all the operations into one data structure ( if there is any, what we can use?)

    Friday, May 13, 2016 9:36 AM
  • Hello,

    It seems that you are describing the same issue as described in the following case, please try to check my reply:
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/06045be0-4dba-4d10-949a-f6b29b25945d/porttype-is-coming-as-null-in-wsdl-parsing?forum=wcf .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 13, 2016 9:38 AM
    Moderator
  • Hi Peng, 

     know that you are travesring and getting port types. 

    Is there any way to add import section to my description object?

    Friday, May 13, 2016 11:39 AM
  • Peng, 

    That Thread is  incomplete. In fact I have some questions over there :)

    Wednesday, May 18, 2016 12:28 PM
  • >>Is there any way to add import section to my description object?

    Do you mean that you want to retrieve the PortType object from the variable named subDescription and assign them to variable named myDescription?  If it’s the case, please refer to the following code:

    string wsdlUrl = "https://domainws.ficora.fi/fiDomain/DomainNameWS_FicoraDomainNameWS.svc?wsdl"; //"http://localhost/MessageWithWindows/Service.svc?wsdl"
                XmlTextReader myReader = new XmlTextReader(wsdlUrl);
                if (ServiceDescription.CanRead(myReader))
                {
                    ServiceDescription myDescription = ServiceDescription.Read(myReader);
    
                    //ImportCollection ic = myDescription.Imports;
                    foreach (Import im in myDescription.Imports)
                    {
                        string wsdl2 = im.Location;
                        XmlTextReader myReader2 = new XmlTextReader(wsdl2);
                        if (ServiceDescription.CanRead(myReader2))
                        {
                            ServiceDescription subDescription = ServiceDescription.Read(myReader2);
    
                            foreach(PortType pt in subDescription.PortTypes)
                            {
                                myDescription.PortTypes.Add(pt);
                            }
                        }
                    }
    
                    foreach (PortType pt in myDescription.PortTypes)
                    {
                        foreach (Operation op in pt.Operations)
                        {
                            Console.WriteLine("{0}", op.Name);
                        }
                    }
                }
    


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 20, 2016 1:28 AM
  • Hi Bheemanapally,

    Our engineer have replied the issue with some code snippet, please refer to:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/06045be0-4dba-4d10-949a-f6b29b25945d/porttype-is-coming-as-null-in-wsdl-parsing?forum=wcf .

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 20, 2016 8:10 AM