【问题标题】:You can not serialize member asp asmx你不能序列化成员 asmx
【发布时间】:2016-07-14 07:16:13
【问题描述】:

我在发送具有 3 个属性的对象时遇到问题,问题在于发送时的客户数组我有以下错误对象:

您不能序列化成员。因为它是一个界面。

如果客户 ws 的财产运作良好。 我尝试了各种方法来消除错误,但似乎没有一个工作留下代码片段,以便他们可以给我他们的观点。非常感谢

public class CustomersResponse
{
    public bool Success { get; set; }
    public string Error { get; set; }
    public customer[] ListCustomers { get; set; }
}

ws的代码是

/// <summary>
/// 
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class wsCustomers : System.Web.Services.WebService
{
    [WebMethod]
    public CustomersResponse CustomersResult()
    {
        CustomersResponse customers = new CustomersResponse ();
        try
        {
            using (var context = new DataContext())
            {
                customers.Success = true;
                customers .Error = string.Empty;
            }
        }
        catch (Exception ex)
        {
            customers .Success = false;
            customers .Error = ex.Message.ToString();
        }

        return customers ;
    }
}

如果我删除属性 ListCustomers ws 运行良好,如果我标记错误:(

【问题讨论】:

标签: c# asp.net web-services


【解决方案1】:

您需要将[Serializable] 元标记放在您的客户类别之前。

[Serializable]
public class customer
{

//....

}

【讨论】:

    【解决方案2】:

    我已经可以解决问题a.cual 是我使用的一个名为customers EntityFramework 的模型的解决方案。另一个类是使用与客户相同的属性创建的,并且在编译应用程序时已经可以工作了,因为它会影响客户并因此标记该异常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-20
      • 2010-12-06
      • 1970-01-01
      • 2011-05-27
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      • 2013-06-23
      相关资源
      最近更新 更多