如何从Webmethod调用私有方法 [英] How Can I Call Private Method From Webmethod

查看:88
本文介绍了如何从Webmethod调用私有方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在Webservice文件中有私有的Webmethod,我想从WebForm中调用它。我怎么能这样做?

我这样打电话它不起作用。

Hi all , i have private int Webmethod in Webservice file and i want to call it from WebForm . How can i make this ?
I call like this and it doen't work .

protected void Button_Click(object sender, EventArgs e)
       {
        int x = Namespace.WebService1.GetPriv(string a, string b)

       }



错误


Error

' Namespace.WebService1.GetPriv(string , string)' is inaccessible due to its protection level .

推荐答案

不,你不能。

如果你想在另一个项目中访问,你需要制作方法 public



public

类型或成员可以通过同一程序集中的任何其他代码或引用它的另一个程序集来访问。

私人

只能通过同一类或结构中的代码访问类型或成员。



访问修饰符 [ ^ ]

辅助功能级别 [ ^ ]





-KR
No, you cannot.
You need to make the method public if you want to access in another project.

public
The type or member can be accessed by any other code in the same assembly or another assembly that references it.
private
The type or member can be accessed only by code in the same class or struct.

Access Modifiers[^]
Accessibility Levels[^]


-KR


这篇关于如何从Webmethod调用私有方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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