簡體   English   中英

我如何從C#中的類對象提取字段

[英]How can i extract fields from a class object in c#

我有一堂課,有一些屬性

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;
}

它非常簡單,但請幫助我,您也可以建議我一些最佳的替代方法。 謝謝,

您需要具有類型為SendData的參數,該類型應該存在於Web服務應用程序中,並且SendData中的應用程序訪問。

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 
}

我們應該在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.

無法將對象發送到SOAP Web服務

再次感謝大家。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM