将对象返回到UI [英] Returning Objects to UI

查看:100
本文介绍了将对象返回到UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用ASP.NET Web服务开发应用程序


我想将Web服务保持为业务逻辑层基本上我的ASP.NET页面将调用webservice并且web服务将返回适当的数据,在某些情况下我需要返回我自己的类对象但是当我尝试返回某个类的对象时我得到一个错误


'/ WebService1'应用程序中的服务器错误。




无法序列化成员System.ComponentModel.Component.Site类型为System.ComponentModel.ISite,因为它是一个接口。


我需要序列化我的对象,然后才能从Web服务(可能使用XMLSerialzer.Serialize)?


如果是这种情况那么webservice的用途是什么?我尝试返回一些.NET对象(SQLConnection等)并且得到了相同的错误!!。


因为它还提供了SOAP和IIS集成,所以不值得使用.NET Remoting。哪一个更好?


请帮助...感谢预期

解决方案

HI.guy。


webservice也使用XMLSerializer来序列化传递给webmethod的对象返回值或参数。


如果对象是被序列化有任何属性是接口类型。上面的错误将被抛出。


但是,为什么要返回像"SQLConnection"这样的组件?等。


用于WebService模式。只返回数据对象。如果有接口类型属性,则将XmlIgnoreAttribute分配给它们


阻止它们被串行化。


Matt。


Hi,

I am developing an application using ASP.NET web services

I want to keep web Services as the business logic layer so basically my ASP.NET page will call the webservice and the web service will return appropriate data, in some cases I need to return my own class objects but when I try to return an object of some class i get an error

 Server Error in '/WebService1' Application.


Cannot serialize member System.ComponentModel.Component.Site of type System.ComponentModel.ISite because it is an interface.

do I need to serialise my objects before returning them from a Webservice (probably using XMLSerialzer.Serialize)?

if this is the case then what is the use of a webservice??, I tried returning some .NET objects as well (SQLConnection etc) and got the same error!!.

is it not worth to use .NET Remoting instead since that also provides SOAP and IIS integration. which one is better?

Please help ... thanks in anticipation

解决方案

HI.guy.

the webservice also use XMLSerializer to Serialize the object return value or parameter passed to webmethod.

if the object that would be serialized  has any property which is a Interface type. the above error will be throwed.

but , why you want to return component like "SQLConnection" etc.

for WebService pattern. only data object be return. and if there are Interface type property , XmlIgnoreAttribute will be assigned to them to

prevent them being serrialized.

Matt.


这篇关于将对象返回到UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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