Web服务错误序列化成员

时间:2012-02-28 19:30:59

标签: asp.net web-services serialization

当我运行我的网络服务时,我想问一下网络服务 调试时我没有收到错误,但是当我运行它时, 我在浏览器上收到此错误:

Server Error in '/' Application.
Cannot serialize member System.Web.UI.Control.Site of type System.ComponentModel.ISite because it is an interface.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

我有谷歌,但我没有得到答案。即使我使用另一个System.Web.UI,它仍然相同 请有人帮帮我

无论如何,这是我的网络服务代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace Rabbitry
{
    /// <summary>
    /// Summary description for WebService1
    /// </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 KaryawanWS : System.Web.Services.WebService
    {
        public RabbitryDB _db = new RabbitryDB();

        [WebMethod] // get all employee data
        public Karyawan[] GetAllKaryawan()
        {
            return _db.Karyawans.ToArray();
        }

        [WebMethod] //get employee data by ID
        public Karyawan GetKaryawanByID(string NIK)
        {
            return _db.Karyawans.FirstOrDefault(x => x.NIK == NIK);
        }

        [WebMethod] // inserting new employee
        public void TambahKaryawan(string NIK, string ktpKaryawan, string namaKaryawan, string alamatKaryawan, 
                                    string telpKaryawan, string hpKaryawan, string joinKaryawan, string statusKaryawan,
                                    string pwd, string role)
        {
            DateTime join;
            bool rol, status;

            DateTime.TryParse(joinKaryawan, out join);
            bool.TryParse(role, out rol);
            bool.TryParse(statusKaryawan, out status);

            Karyawan k = new Karyawan
            {
                NIK = NIK,
                ktpKaryawan = ktpKaryawan,
                namaKaryawan = namaKaryawan,
                alamatKaryawan = alamatKaryawan,
                telpKaryawan = telpKaryawan,
                hpKaryawan = hpKaryawan,
                joinKaryawan = join,
                statusKaryawan = status
            };

            Login l = new Login
            {
                NIK = NIK,
                Password = pwd,
                role = rol
            };

            _db.Karyawans.InsertOnSubmit(k);
            _db.Logins.InsertOnSubmit(l);
            _db.SubmitChanges();
        }

        [WebMethod] //edit employee data
        public void EditKaryawan(string NIK, string alamatKaryawan,
                                    string telpKaryawan, string hpKaryawan, string statusKaryawan)
        {
            bool status;
            bool.TryParse(statusKaryawan, out status);

            Karyawan k = _db.Karyawans.FirstOrDefault(x => x.NIK == NIK);
            if (k != null)
            {
                k.alamatKaryawan = alamatKaryawan;
                k.telpKaryawan = telpKaryawan;
                k.hpKaryawan = hpKaryawan;
                k.statusKaryawan = status;
                _db.SubmitChanges();
            }
        }


        [WebMethod] //deleting emplyee data
        public void HapusKaryawan(string NIK)
        {
            Karyawan k = _db.Karyawans.FirstOrDefault(x => x.NIK == NIK);
            Login l = _db.Logins.FirstOrDefault(x => x.NIK == NIK);
            if (k != null)
            {
                _db.Logins.DeleteOnSubmit(l);
                _db.Karyawans.DeleteOnSubmit(k);
                _db.SubmitChanges();
            }            
        }
    }
}

1 个答案:

答案 0 :(得分:1)

我已经完成了这件事

问题出在DBML名称中 S的表名不能由S结束所以我从Kamus改为Kamu并且效果很好