28 Eylül 2012 Cuma

asp.net te windows service kullanımı

[ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        [OperationContract]
        string GetUserInfo(int ID);

        [OperationContract()]
        IEnumerable<User> GetUserList();
    }

    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }

    [DataContract]
    public class User
    {
        public int ID { get; set; }
        public string name { get; set; }
        public string password { get; set; }
        public User() { }
        public User(int _ID, string _name, string _password)
        {
            this.ID = _ID;
            this.name = _name;
            this.password = _password;
        }
    }    


//**********************************//
public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }

        public string GetUserInfo(int ID)
        {
            string sb = "";
            User us = new User() { ID = 3, name = "hakan", password = "passsssssss" };
            if (us.ID == ID)
            {
                sb = us.ID + " : " + us.name + " : " + us.password;
            }
            return sb;
        }

        public IEnumerable<User> GetUserList()
        {
            NSGenel.Genel.MesajGoster("ok");
            return new List<User>() { new User() { ID = 3, name = "asdfsdf", password = "psdfsf" } };
            //return (List<User>)(us.Add(new User { ID = 3, name = "dfgdfg", password = "passs" }));
            
        }
    }
//******************************//
servisi projemize ekledikten sonra
ServiceReference1.IService1 service = new ServiceReference1.Service1Client();
service örneğiyle yazdığımız metodlara ulaşabiliriz.



Hiç yorum yok:

Yorum Gönder