Kilitli accessing the class through web service

  • 04 Nisan 2012 Çarşamba 04:45
     
     

    hi,

    can anybody help me, how to access the class which will return by the web serrvice. my class will contain username and email.and webservice will return this class

    thanks,

    prathap


    thanks, prathap

Tüm Yanıtlar

  • 08 Nisan 2012 Pazar 07:11
     
     

    Hi Prathap,

    Check below Web Service Tutorial

    http://www.codeproject.com/Articles/863/Your-first-C-Web-Service

    Regards

    Purvi

  • 09 Nisan 2012 Pazartesi 18:36
     
     

    You need to create the proxy of the webservice in your project OR add web reference of the web service (which will in turn create proxy).

    In your code, add the following lines -

    localhost.Service1 svc = new Application1.localhost.Service1();

    object obj= svc.getEmployee();

    Employee emp = new Employee();

    emp = (Employee)obj;

    now you can use the code emp.username.ToString() to get the username

    and emp.email.ToString() to get the email.


    Thanks, AT

  • 16 Nisan 2012 Pazartesi 08:30
     
     

    Hello,

    Check out the link below. IT will help you.

    http://www.codeproject.com/Articles/3686/Exposing-custom-made-classes-through-a-Webservice

    http://msdn.microsoft.com/en-us/library/b65d88sc%28v=vs.90%29.aspx

  • 18 Nisan 2012 Çarşamba 04:48
     
      Kod İçerir

    You can return an instance of your class from Asmx Web method similar like other data type.But the only thing you need to remember is your class should be decorated with [Serializable] attribute and all property of your class should not be of complex type.

    Below code snippet will help you.

     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
       [ToolboxItem(false)]
       public class Service1 : System.Web.Services.WebService
        {
            [WebMethod]
            public Employee GetEmployee()
            {
                return new Employee();
            }
        }
        [Serializable]
        public class Employee {
            private string userName;
            public string UserName{
                get { return userName; }
                set { userName= value; }
            }
            private string email;
            public string Email
            {
                get { return email; }
                set { email= value; }
            }
        }


    Lingaraj Mishra

  • 18 Nisan 2012 Çarşamba 14:20
    Moderatör
     
     
    Actually, the [Serializable] attribute is not used by the XML Serializer.

    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects