Client code for Web Method Returning a complex Custom data type

csharp Belgium
  • 12 years ago

    Hi,I am facing a problem in capturing and retreiving data from a webmethod response.I am calling web methods on remote server.So I have included the web reference of the webservice in my Vs2005 solution.But the main problem is the webmethods are returning custom Array datatypes.The coustom data types are the other class types.I am facing problem in accessing the returned data.I think my client side code is creating the main problem.Please find the Below code(Auto generated code).and Please help me.

    The Defination webmethod which I am calling.which is a part of a class called.

    public partial class hbcontent : System.Web.Services.Protocols.SoapHttpClientProtocol {

    -----Many other Parametrs/methods Below one is the sample---

    [System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="http://remote.api", ResponseNamespace=http://remote.api)]

            [return: System.Xml.Serialization.SoapElementAttribute("getCountryDataReturn")]

            public Map getCountryData(string key, string language, string country) {

                object[] results = this.Invoke("getCountryData", new object[] {

                            key,

                            language,

                            country});

                return ((Map)(results[0]));

            }

    }----Definition of the other classes  :---- 

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.2344")]

        [System.SerializableAttribute()]

        [System.Diagnostics.DebuggerStepThroughAttribute()]

        [System.ComponentModel.DesignerCategoryAttribute("code")]

    [System.Xml.Serialization.SoapTypeAttribute(Namespace="http://xml.apache.org/xml-soap")]

        public partial class Map {       

            private mapItem[] itemField;       

            public mapItem[] item {

                get {

                    return this.itemField;

                }

                set {

                    this.itemField = value;

                }

            }

        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.2344")]

        [System.SerializableAttribute()]

        [System.Diagnostics.DebuggerStepThroughAttribute()]

        [System.ComponentModel.DesignerCategoryAttribute("code")]   [System.Xml.Serialization.SoapTypeAttribute(Namespace="http://xml.apache.org/xml-soap")]

        public partial class mapItem {

            private object keyField;

            private object valueField;

            [System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]

            public object key {

                get {

                    return this.keyField;

                }

                set {

                    this.keyField = value;

                }

            }

            [System.Xml.Serialization.SoapElementAttribute(IsNullable=true)]

            public object value {

                get {

                    return this.valueField;

                }

                set {

                    this.valueField = value;

                }

            }

        }

    WSDL file for the corresponding section:

    <?xml version="1.0" encoding="UTF-8"?>

    <wsdl:definitions targetNamespace="http://remote.api" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://remote.api" xmlns:intf="http://remote.api" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://rpc.xml.coldfusion" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <!--WSDL created by Macromedia ColdFusion MX version-->

     <wsdl:types>

      <schema targetNamespace="http://rpc.xml.coldfusion" xmlns="http://www.w3.org/2001/XMLSchema">

       <import namespace="http://remote.api"/>

       <import namespace="http://xml.apache.org/xml-soap"/>

       <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>

       <complexType name="CFCInvocationException">

        <sequence/>

       </complexType>

       <complexType name="QueryBean">

        <sequence>

         <element name="columnList" nillable="true" type="impl:ArrayOf_xsd_string"/>

         <element name="data" nillable="true" type="impl:ArrayOfArrayOf_xsd_anyType"/>

        </sequence>

       </complexType>

      </schema>

      <schema targetNamespace="http://xml.apache.org/xml-soap" xmlns="http://www.w3.org/2001/XMLSchema">

       <import namespace="http://remote.api"/>

       <import namespace="http://rpc.xml.coldfusion"/>

       <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>

       <complexType name="mapItem">

        <sequence>

         <element name="key" nillable="true" type="xsd:anyType"/>

         <element name="value" nillable="true" type="xsd:anyType"/>

        </sequence>

       </complexType>

       <complexType name="Map">

        <sequence>

         <element maxOccurs="unbounded" minOccurs="0" name="item" type="apachesoap:mapItem"/>

        </sequence>

       </complexType>

      </schema>

    My client Code:

    static void Main(string[] args)

       {

    hbcontent hbc = new hbcontent();

    Map  map2 = new Map();

    map2 = (Map)hbc.getCountryData("Key12345", "en", "new-zealand");           

    }

    When run the above code nothing is returned to the map2.But the web method is returning the data,which I can see using some Http tools like Wfecth and fiddler.

    The sample data captured in fiddler is:

    <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

     <soapenv:Body>

      <ns1:getCountryDataResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://remote.api">

       <getCountryDataReturn xsi:type="ns2:Map" xmlns:ns2="http://xml.apache.org/xml-soap">

        <item xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">

         <key xsi:type="soapenc:string">RESPONSE</key>

         <value xsi:type="ns2:Map">

          <item>

           <key xsi:type="soapenc:string">LOCATIONS</key>

           <value soapenc:arrayType="xsd:anyType[10]" xsi:type="soapenc:Array">

            <value xsi:type="ns2:Map">

             <item>

              <key xsi:type="soapenc:string">LNAME</key>

              <value xsi:type="soapenc:string">Abel Tasman</value>

             </item>

             <item>

              <key xsi:type="soapenc:string">INTRO</key>

              <value xsi:type="soapenc:string"></value>

             </item>

             <item>

              <key xsi:type="soapenc:string">IMG</key>

              <value xsi:type="soapenc:string"></value>

             </item>

             <item>

              <key xsi:type="soapenc:string">NAME</key>

              <value xsi:type="soapenc:string">abel-tasman</value>

             </item>

             <item>

              <key xsi:type="soapenc:string">LANGUAGE</key>

              <value xsi:type="soapenc:string">en</value>

             </item>

             <item>

              <key xsi:type="soapenc:string">ID</key>

              <value xsi:type="soapenc:int">9862</value>

             </item>

            </value>

            <value xsi:type="ns2:Map">

             <item>

              <key xsi:type="soapenc:string">LNAME</key>

              <value xsi:type="soapenc:string">Ahipara</value>

             </item>

             <item>

              <key xsi:type="soapenc:string">INTRO</key>

              <value xsi:type="soapenc:string"></value>

             </item>

             <item>

              <key xsi:type="soapenc:string">IMG</key>

              <value xsi:type="soapenc:string"></value>

             </item>

             <item>

              <key xsi:type="soapenc:string">NAME</key>

              <value xsi:type="soapenc:string">ahipara</value>

             </item>

             <item>

              <key xsi:type="soapenc:string">LANGUAGE</key>

              <value xsi:type="soapenc:string">en</value>

             </item>

             <item>

              <key xsi:type="soapenc:string">ID</key>

              <value xsi:type="soapenc:int">9646</value>

             </item>

            </value>       

           </value>

          </item>

          <item>

           <key xsi:type="soapenc:string">CONTENT</key>

           <value xsi:type="ns2:Map">

            <item>

             <key xsi:type="soapenc:string">LNAME</key>

             <value xsi:type="soapenc:string">New Zealand</value>

            </item>

            <item>

             <key xsi:type="soapenc:string">EXCHRATE</key>

             <value xsi:type="soapenc:decimal">1.3170</value>

            </item>

            <item>

             <key xsi:type="soapenc:string">INTRO</key>

             <value xsi:type="soapenc:string"></value>

            </item>

            <item>

             <key xsi:type="soapenc:string">CURRENCY</key>

             <value xsi:type="soapenc:string">New Zealand Dollars</value>

            </item>

            <item>

             <key xsi:type="soapenc:string">IMG</key>

             <value xsi:type="soapenc:string"></value>

            </item>

            <item>

             <key xsi:type="soapenc:string">CONTINENT</key>

             <value xsi:type="soapenc:string">au</value>

            </item>

            <item>

             <key xsi:type="soapenc:string">NAME</key>

             <value xsi:type="soapenc:string">new-zealand</value>

            </item>

            <item>

             <key xsi:type="soapenc:string">LANGUAGE</key>

             <value xsi:type="soapenc:string">en</value>

            </item>

            <item>

             <key xsi:type="soapenc:string">ID</key>

             <value xsi:type="soapenc:int">212</value>

            </item>

           </value>

          </item>

         </value>

        </item>

        <item>

         <key xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">METHOD</key>

         <value xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">getCountryData(KEY=******,LANGUAGE=en,COUNTRY=new-zealand)</value>

        </item>

       </getCountryDataReturn>

      </ns1:getCountryDataResponse>

     </soapenv:Body>

    </soapenv:Envelope>I need to retreive the above data and use it on my presentation layer.please help me with this.it would be a great help for me.

    Thanks in advance.

     

     

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Nine people can't make a baby in a month.” - Fred Brooks