如何在asp.net webservice中创建公共属性(get; set)并在客户端访问。 [英] How to make public properties(get;set) in asp.net webservice and access at client end.

查看:152
本文介绍了如何在asp.net webservice中创建公共属性(get; set)并在客户端访问。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,我正在尝试这个。在asp.net webservice中。并尝试在客户端访问它。





WebService

Dear I am trying this. in asp.net webservice. and trying to access at it at client end.


WebService

public class Service1 : System.Web.Services.WebService
    {
        private static string _NPI=string.Empty;
        public static string NPI
        {
            get
            {
                return _NPI;
            }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    _NPI = value;
                }
            }
        }

       
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public int Add(int a,int b)
        {
            return a + b;
        }

        [WebMethod]
        public int Min(int a, int b)
        {
            return a - b;
        }
    }





客户





Client

ServiceReference1.Service1SoapClient obj = new ServiceReference1.Service1SoapClient();
                int a = obj.Add(5, 8);
                a = obj.Min(a, 10);
            //Methods are accessible but why not i am able to get,set property.
            //Please help?







谢谢

等待FOR RESPONSE?




THANKS
WAITING FOR RESPONSE?

推荐答案

Hi MuhammadUsman1



因为字符串NPI是静态的你不需要创建对象你可以像这样访问它。



ServiceReference1.Service1.NPI =任何字符串;



string var = ServiceReference1.Service1.NPI;
Hi MuhammadUsman1

since string NPI is static you don need to create object you can access it like this.

ServiceReference1.Service1.NPI="any string";

string var= ServiceReference1.Service1.NPI;


这篇关于如何在asp.net webservice中创建公共属性(get; set)并在客户端访问。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆