在asp.net web服务,传递到WebControl的一个WebMethod [英] in asp.net WebService, passing a WebControl to a WebMethod

查看:265
本文介绍了在asp.net web服务,传递到WebControl的一个WebMethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用asp.net 4,C#,Visual Studio 2010。
我通过调用具有的WebControl作为参数的Web服务方法面临的一个问题。

I'm using asp.net 4 ,C# ,VS 2010. I'm facing a problem by calling a web service method which has a WebControl as a parameter.

/// <summary>
/// Summary description for FormsViews
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]

public class FormViews : System.Web.Services.WebService
{
    [WebMethod]
    public void SetCaption(System.Web.UI.WebControls.Button bt)
    {
        //Code...
    }
}

它编译没有任何错误。
于运行时我得到这个消息:

It compiles with no errors. On RunTime I get this message:

XML元素从命名空间空间EnableTheming已经是present在当前范围内。使用XML属性来指定元素另一种XML名称或名称空间。

The XML element 'EnableTheming' from namespace 'namespace' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element.

能否请你解释为什么web服务不接受的WebControl,如何处理这个问题呢?

Can you please explain why the webService doesn't accept a WebControl and how to handle this issue?

推荐答案

Web服务不接受的WebControl,因为它是不可序列化和良好的Web服务设计并不直接操纵观点或用户界面。逻辑的意见应留在你的意见,而不是在什么通常是业务层。处理视图或网页语言支持的典型方法是使一个Web服务,指示页面应该支持的语言请求,并返回标签作为键/值对的列表。关键是控制的ID和值是什么,应在控制显示。这只是必要的,如果你的网页使用了大量的Ajax。如果你只是渲染服务器上的页面,那么你可以当他们在服务器上呈现的正确的语言填充控制。 这里是一个MSDN文章,讨论如何做到这一点。

The web service does not accept a WebControl because it is not serializable and good web service design does not directly manipulate views or user interfaces. Logic for your views should be left in your views, not in what is typically the business layer. A typical way to handle language support in a view or web page is to make a request to a web service that indicates the language the page should support and it returns a list of labels as key/value pairs. The key is an ID for the control and the value is what should be displayed in the control. This is only necessary if your web page uses a lot of Ajax. If you are just rendering the page on the server then you can populate the controls with the correct language when they are rendered on the server. Here is an MSDN article that discusses how to do this.

这篇关于在asp.net web服务,传递到WebControl的一个WebMethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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