如何通过一个接口对象以一个WebMethod? [英] How to pass an Interface object to a WebMethod?
本文介绍了如何通过一个接口对象以一个WebMethod?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有网方法,采取界面对象作为参数,每当我尝试访问我得到异常说的方法.NET Web服务:的无法序列会员产品IProduct,因为它是一个接口。 的
任何建议来解决这个问题?
[WebMethod的]
公共双CalculateTotal(IProduct产品,INT数量)
{
返回product.Price *数量;
}
解决方案
喜PRASHANT请尝试做这样的..
在发生这种
[WebMethod的]
公共双CalculateTotal(IProduct产品,INT数量)
{
返回product.Price *数量;
}
只需添加一个抽象类becoz你需要一个类型序列化。
[Serializable接口]
公共抽象类ProductAbstract:IProduct
{
//定义的所有方法/接口IProduct这里的属性抽象方法/属性
}
[WebMethod的]
公共双CalculateTotal(ProductAbstract产品,INT数量)
{
返回product.Price *数量;
}
I have a .Net web service with web method which take a Interface object as parameter, whenever I try to access the method I get exception saying : Cannot serialize member Product IProduct because it is an interface.
Any suggestions to solve the problem ??
[WebMethod]
Public double CalculateTotal(IProduct product, int Quantity)
{
return product.Price * Quantity;
}
解决方案
hi prashant please try to do like this..
In place of this
[WebMethod]
Public double CalculateTotal(IProduct product, int Quantity)
{
return product.Price * Quantity;
}
Just Add an abstract class becoz you need a type to serialize it..
[Serializable]
public abstract class ProductAbstract : IProduct
{
// define all methods/attributes of interface IProduct here as abstract methods/attributes
}
[WebMethod]
Public double CalculateTotal(ProductAbstract product, int Quantity)
{
return product.Price * Quantity;
}
这篇关于如何通过一个接口对象以一个WebMethod?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文