p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   .NET Web Services (http://p2p.wrox.com/forumdisplay.php?f=102)
-   -   Web Method Returning a complex Custom data type. (http://p2p.wrox.com/showthread.php?t=69382)

saisunil1978 July 15th, 2008 05:38 AM

Web Method Returning a complex Custom data type.
 
Hi,
I am facing a problem in capturing and retreving 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.SoapHttpClientProtoc ol
{

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

[System.Web.Services.Protocols.SoapRpcMethodAttribu te("", RequestNamespace="http://remote.api", ResponseNamespace="http://remote.api")]
        [return: System.Xml.Serialization.SoapElementAttribute("get CountryDataReturn")]
        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("Sy stem.Xml", "2.0.50727.2344")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.SoapTypeAttribute(Namespa ce="http://xml.apache.org/xml-soap")]
    public partial class Map {

        private mapItem[] itemField;

        /// <remarks/>
        public mapItem[] item {
            get {
                return this.itemField;
            }
            set {
                this.itemField = value;
            }
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("Sy stem.Xml", "2.0.50727.2344")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("c ode")]
    [System.Xml.Serialization.SoapTypeAttribute(Namespa ce="http://xml.apache.org/xml-soap")]
    public partial class mapItem {

        private object keyField;

        private object valueField;

        /// <remarks/>
        [System.Xml.Serialization.SoapElementAttribute(IsNu llable=true)]
        public object key {
            get {
                return this.keyField;
            }
            set {
                this.keyField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.SoapElementAttribute(IsNu llable=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: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=ne w-zealand)</value>
    </item>
   </getCountryDataReturn>
  </ns1:getCountryDataResponse>
 </soapenv:Body>
</soapenv:Envelope>


I need to retreve 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.:)





All times are GMT -4. The time now is 12:07 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.