【发布时间】:2012-09-19 10:18:23
【问题描述】:
我正在使用 asp.net 4、C#、VS 2010。 我在调用一个以 WebControl 作为参数的 Web 服务方法时遇到了问题。
/// <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...
}
}
它编译没有错误。 在运行时我收到这条消息:
命名空间“namespace”中的 XML 元素“EnableTheming”已存在于当前范围内。使用 XML 属性为元素指定另一个 XML 名称或命名空间。
您能否解释一下为什么 webService 不接受 WebControl 以及如何处理这个问题?
【问题讨论】:
-
你为什么需要这样的东西?一个按钮属于它的页面,不应该被序列化。
-
你想用这种方法达到什么目的?我可以看到它被称为 SetCaption() 但我不明白你为什么要发送按钮控件?
-
更完整的函数接收 System.Web.UI.ControlCollection,我在其中将所有标题/文本等从我的数据库设置到每个控件。这是通过抛出的 aspx 页面 (this.Page.Controls) .我为问题简化了它。这样我可以很容易地改变语言。但是为什么会这样呢?
标签: asp.net web-services webmethod asp.net-webcontrol