C# Web Service 从 WinForms 应用程序将对象作为 null 返回

本文关键字:对象 null 返回 应用程序 Web Service WinForms | 更新日期: 2023-09-27 18:35:55

我从我的 Web 服务返回一个数组,如下所示:

   [WebMethod]
   public Test_UserData[] GetLimitUsers(int min, int max)
   {
   return UserServiceLayer.GetLimitUsers(min, max);    
   }

如果我从浏览器调用此 Web 服务,则按预期以 XML 格式显示数组和内容。

然后,我将 Web 引用添加到 winforms 项目中。在我的裸露中,我在两个返回普通旧对象的项目之间以相同的方式连接了其他 Web 服务,并且它们工作正常。

UserWS.UserWS userWebService = new UserWS.UserWS();
Test_UserData[] testUserData = userWebService.GetLimitUsers(1, 2);

但是,当我调用此 Web 服务时,我得到了预期的对象数量,但所有字段均为空,布尔值为 false。(与数组、列表和 ienumerable 的行为相同。

有人可以解释为什么我得到了正确的对象,但它们都被"无效"了?

编辑:

<Test_UserData>
<Id_ValueIncluded>true</Id_ValueIncluded>
<Id>
<Value xmlns="http://www.blah.co.uk/JamesTest/Data/">100001</Value>
<References xmlns="http://www.blah.co.uk/JamesTest/Data/"/>
</Id>
<ExtensionData_ValueIncluded>true</ExtensionData_ValueIncluded>
<Password_ValueIncluded>true</Password_ValueIncluded>
<Password>h</Password>
<UserName_ValueIncluded>true</UserName_ValueIncluded>
<UserName>h</UserName>
<OutputData>
<Type_ValueIncluded>true</Type_ValueIncluded>
<Type>Test_User</Type>
</OutputData>
</Test_UserData>

C# Web Service 从 WinForms 应用程序将对象作为 null 返回

最后,

当将asmx文件与winforms一起使用时,这是一个命名空间问题。