我正在使用ASP.NET C#创建Web服务。我从WebService发送各种数据类型,因此我使用以下结构。
我使用两种客户端类型,JavaScript 和 C#.NET Windows Form。当我从 JavaScript 调用时,没有问题,osr.data 填充了 WS_User。因此,我可以轻松地使用 osr.data.id。但是当我从 C#.NET 调用时(代理使用“添加 Web 引用”生成),我可以成功调用,但当结果到达时,我会收到一个 Soap 异常。
{System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: 服务器无法处理请求。 ---> System.InvalidOperationException: 生成 XML 文档时出错 ... ... }
我错过了什么?我猜对象定义不正确,导致问题。有哪些解决方法?
谢谢。
Maksud
补充:
如果添加以下虚拟方法,则它可以正常工作。希望能帮助您找到解决方案。
public enum WS_ServiceResponseResult
{
Success,
Failure,
}
public class WS_ServiceResponse
{
public WS_ServiceResponseResult result { get; set; }
public object data { get; set; }
}
public class WS_User
{
public long id{ get; set; }
public string name{ get; set; }
}
Web服务示例方法
[WebMethod(EnableSession = true)]
public WS_ServiceResponse LogIn(string username, string pasword)
{
WS_ServiceResponse osr = new WS_ServiceResponse();
long userID = UserController.checkLogin(username, pasword);
if (userID != 0)
{
osr.result = WS_ServiceResponseResult.Success;
osr.data = new WS_User() { id = userID, name = username };
}
else
{
osr.result = WS_ServiceResponseResult.Failure;
osr.data = "Invalid username/password!";
}
return osr;
}
我使用两种客户端类型,JavaScript 和 C#.NET Windows Form。当我从 JavaScript 调用时,没有问题,osr.data 填充了 WS_User。因此,我可以轻松地使用 osr.data.id。但是当我从 C#.NET 调用时(代理使用“添加 Web 引用”生成),我可以成功调用,但当结果到达时,我会收到一个 Soap 异常。
{System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: 服务器无法处理请求。 ---> System.InvalidOperationException: 生成 XML 文档时出错 ... ... }
我错过了什么?我猜对象定义不正确,导致问题。有哪些解决方法?
谢谢。
Maksud
补充:
如果添加以下虚拟方法,则它可以正常工作。希望能帮助您找到解决方案。
[WebMethod]
public WS_User Dummy()
{
return new WS_User();
}