值传递给一个对象,以Web服务的WebMethod C# [英] pass values to an object to webservices webmethod C#

查看:322
本文介绍了值传递给一个对象,以Web服务的WebMethod C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要传递一个对象作为参数传递给Web服务网络method..i没有问题,这样做..我面临的问题是..我需要从知道我应该把类的价值观

I need to pass an object as a parameter to the web service web method..i have no issues doing that.. the problem i am facing is.. i need to know from where i should pass the values of the class

例如我有有2个属性的名字一类人,姓..

for example i have a class person which has 2 attributes firstname and lastname..

我传递这个人对象将WebMethod像

i am passing this person object to the webmethod something like

[webmethod]
public string setData(Person p)
    {
//insert firstname and last name to database
}

现在我的问题是我在哪里可以赋值给Person类,这样我可以把它导入数据库?

now my question is from where can i assign values to the person class so that i can get it into the database?

感谢

推荐答案

我觉得你应该通过类值传递给web服务。你可以从类中提取值并传送到数据库查询。这会给你更多的效率超过添加和删除参数。

I think you should pass the values through the class to webservice. And you can extract values from the class and send to the database query. This will give you more efficiency over adding and removing parameters.

fun ServiceCall()
{
    Person P
    P.fName='First Name'
    p.lName='Last Name'
    serviceClas.setData(P)
}

public string setData(Person p)    
{ 
    //insert firstname and last name to database 

    SqlCommand command = new SqlCommand();    
    SqlCommand command = new SqlCommand  ("Proc_name", connection);      
    command.CommandType = CommandType.StoredProcedure;    
    SqlParameter parameter1 = new SqlParameter();    
    parameter.ParameterName = "@Param1";     
    parameter.SqlDbType = SqlDbType.NVarChar;
    parameter.Direction = ParameterDirection.Input;     
    parameter.Value = P.fName; 
} 

这篇关于值传递给一个对象,以Web服务的WebMethod C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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