首页 新闻 会员 周边

WebServices 如何改变传进去的引用类型值

0
悬赏园豆:10 [已关闭问题]

客户端:

protected void Button2_Click(object sender, EventArgs e)
{
        
string str = "";
         stuInfo1.StuName
= "test";
         str
= ser.HelloStu(stuInfo1);//传递webservice中的实体类
}

 

WebServices端:

        [XmlInclude(typeof(Student))]
        [WebMethod]
       
public void HelloStu(Student stuInfo)
        {
            stuInfo.StuName
= "改变了!";
           
return stuInfo.StuName;
        }

---------------------------------------------------------
请问,如何做到客户端的stuInfo1的StuName值被改变?

寂灭我有的主页 寂灭我有 | 初学一级 | 园豆:190
提问于:2009-08-25 19:58
< >
分享
其他回答(3)
0

 

一、直接返回,WebServices端:

       

[XmlInclude(typeof(Student))]
[WebMethod]
public string HelloStu(Student stuInfo)
{
stuInfo.StuName
= "改变了!";
return stuInfo.StuName;
}

二、先客户端

protected void Button2_Click(object sender, EventArgs e)
{
string str = "";
stuInfo1.StuName
= "test";
ser.HelloStu(ref stuInfo1);//传递webservice中的实体类
str=
stuInfo1.StuName;
}
再服务器端
[XmlInclude(typeof(Student))]
[WebMethod]
public void HelloStu(ref Student stuInfo)
{
stuInfo.StuName
= "改变了!";
//return stuInfo.StuName;
}

邀月 | 园豆:25475 (高人七级) | 2009-08-25 21:06
0

stuInfo1?客户端?没搞错吧?

izee | 园豆:127 (初学一级) | 2009-08-25 22:38
兄弟,WebService也是B/S的,你从page的服务器代码上调用自己的webservice? 又何必开发webservice呢?
支持(0) 反对(0) izee | 园豆:127 (初学一级) | 2009-08-25 22:41
@izee:小朋友,这个WebService是多个系统调用的,既有b/s的也有c/s的
支持(0) 反对(0) 寂灭我有 | 园豆:190 (初学一级) | 2009-11-20 16:14
0

看来你这个设计只是个demo吧?

如果webservice架构真如此,那架构师就是云彩了

webservice的架构要遵从粗粒度,封装性的原则

Keep Walking | 园豆:73 (初学一级) | 2009-08-26 13:30
0

基于webservice就会走序列化/反序列化的路,因此传递给webservice的stuInfo1和webservice接收到的并不是同一个对象,这个在设计接口的时候必须注意,通常可以设计为将该对象返回:

public Student HelloStu(Student stuInfo) {

    stuInfo.Name = "Changed";

    return stuInfo;

}

客户端:

stuInfo1 = webService.HelloStu(stuInfo1);

我记得webservice是不能用ref和out的

Gray Zhang | 园豆:17610 (专家六级) | 2009-08-26 13:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册