如何使用wcf方法,它是aspx.cs文件中的返回类型列表 [英] how to consume wcf method which is return type list in aspx.cs file
本文介绍了如何使用wcf方法,它是aspx.cs文件中的返回类型列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[operationcontract]
list<导致> method( string name);
[datacontract]
public class 结果
{
[DataMember]
public int no
{
get { return no;}
set {no = value ; }
}
[DataMember]
public int age
{
获取 {返回年龄;}
set {age = value ; }
}
}
在wcf service.cs
public list<导致>方法(字符串名称)
{
sqlcon
sql命令类型过程名称输入,无输出,年龄输出
结果rs = new result();
rs.no = cmd.parameters [ @ no]。值跨度>;
rs.age = cmd.parameters [ @ age]。值跨度>;
list<导致> rls = 新列表<结果取代;
rls。 add (rs);
}
在aspx.cs文件中
ServiceReference2.Service1Client obj2 = new ServiceReference2.Service1Client();
最后在aspx.cs文件中调用wcf服务它是完美的但是当调用wcf方法时返回类型列表显示错误
错误18无法将类型'sample.ServiceReference2.result []'隐式转换为'System.Collections.Generic.List'
如何使用wcf方法,这是aspx.cs文件中的返回类型列表,任何示例代码或任何示例或对我的代码的任何修改
解决方案
< blockquote>添加服务引用选择列表作为数组的返回类型。
检查以下链接中给出的示例
http://www.c-sharpcorner.co m / uploadfile / dhananjaycoder / collection-in-wcf / [ ^ ]
检查另一个例子。
http://www.dotnetspeaks.com/DisplayArticle.aspx?ID=29 [ ^ ]
in iservice.cs
[operationcontract]
list< result> method(string name);
[datacontract]
public class result
{
[DataMember]
public int no
{
get { return no;}
set { no= value; }
}
[DataMember]
public int age
{
get { return age;}
set { age= value; }
}
}
in wcf service.cs
public list< result> method( string name)
{
sqlcon
sql command type procedure name-input,no-output,age-output
result rs=new result();
rs.no=cmd.parameters["@no"].value;
rs.age=cmd.parameters["@age"].value;
list< result> rls=new list< result>;
rls.add(rs);
}
in aspx.cs file
ServiceReference2.Service1Client obj2 = new ServiceReference2.Service1Client();
up to calling wcf service in aspx.cs file it is perfect but when calling wcf method which is in return type list its showing error
Error 18 Cannot implicitly convert type 'sample.ServiceReference2.result[]' to 'System.Collections.Generic.List'
how to consume wcf method which is return type list in aspx.cs file any sample code or any example or any modifications for my code
解决方案
While Adding service reference select list as return type for array.
Check example given in below link
http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/collection-in-wcf/[^]
Check another example.
http://www.dotnetspeaks.com/DisplayArticle.aspx?ID=29[^]
这篇关于如何使用wcf方法,它是aspx.cs文件中的返回类型列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文