我正在尝试在 Web 浏览器中运行 vector.asmx 并收到以下错误。问题是什么?
无法序列化 System.ComponentModel.MarshalByValueComponent.Site 类型的 System.ComponentModel.ISite 成员,因为它是一个接口。
[我的代码]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebApplication2
{
/// <summary>
/// Summary description for Vector
/// </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 Vector : System.Web.Services.WebService
{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
[WebMethod]
public double MagnitudeSquared()
{
return X * X + Y * Y + Z * Z;
}
[WebMethod]
public double Magnitude()
{
return Math.Sqrt(MagnitudeSquared());
}
[WebMethod]
public static Vector operator -(Vector v1, Vector v2)
{
Vector result = new Vector();
result.X = v1.X - v2.X;
result.Y = v1.Y - v2.Y;
result.Z = v1.Z - v2.Z;
return result;
}
[WebMethod]
public static Vector operator +(Vector v1, Vector v2)
{
Vector result = new Vector();
result.X = v1.X + v2.X;
result.Y = v1.Y + v2.Y;
result.Z = v1.Z + v2.Z;
return result;
}
[WebMethod]
public static Vector operator *(Vector v1, double factor)
{
Vector result = new Vector();
result.X = v1.X * factor;
result.Y = v1.Y * factor;
result.Z = v1.Z * factor;
return result;
}
[WebMethod]
public Vector Clone()
{
Vector result = new Vector();
result.X = this.X;
result.Y = this.Y;
result.Z = this.Z;
return result;
}
}
}