Locked accessing the class through web service

  • 4 aprilie 2012 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

Toate mesajele

  • 8 aprilie 2012 07:11
     
     

    Hi Prathap,

    Check below Web Service Tutorial

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

    Regards

    Purvi

  • 9 aprilie 2012 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 aprilie 2012 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 aprilie 2012 04:48
     
      Are cod

    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 aprilie 2012 14:20
    Moderator
     
     
    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