我有一个具有一些属性的类
public class SendData
{
public int MerchantID{get; set;}
public string Name{get; set;}
public int Age{get; set;}
}
然后在按钮上单击并将用户数据初始化为此类的对象。
button_click()
{
SendData senddata = new SendData();
senddata.MerchantID = Convert.ToInt32(txtMerchantid.Text);
senddata.Age = Convert.ToInt32(txtAge.Text);
senddata.Name= txtName.Text;
Webservice1.ReceiveDataService serviceObj = new Webservice1.ReceiveDataService();
public bool result = serviceObj.UpdateData(senddata); // calling web service
if(result) //Here is the scenario
lblresult.Text="Updated";
else
lblresult.Text="Operation unsuccessful";
}
现在我如何在webservice方法中读取此对象的所有字段?
我的网络方法:
public bool updatedata()//How to pass that object here
{
//How can i get those three values in three separate fields in this method like.
string name =""; //that name from UI;
int id = ;//Id from UI
int age= ;//Age from UI
//All the field need to be stored in database those coding will come here.
return true;
}
它很简单,但请帮助我,你也可以建议我一些最佳和替代的方法来实现。 谢谢,
答案 0 :(得分:2)
您需要具有SendData
类型的参数,此类型应存在于Web服务应用程序中,并且可供使用应用程序访问。
public bool updatedata(SendData sendDate)//How to pass that object here
{
//How can i get those three values in three separate fields in this method like.
string name =""; //that name from UI;
int id = ;//Id from UI
int age= ;//Age from UI
}
答案 1 :(得分:-1)
我们应该在web方法之前添加xmlInclude类,以便让类暴露给客户端。
[WebMethod]
[XmlInclude(typeof(Class_Name))]
public bool updatedata(Class_Name ObjectName)
{
string name =ObjectName.Name;
int id = ObjectName.ID;
int age= ObjectName.Age;
//Here the code for database storage etc., etc., and return the value...
return true;
}
Client has to create the proxy class and pass the object to this web service to do the functionalities.
(Can't send object to SOAP Web Service)
再次感谢大家。