且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将自定义对象传递给 Web 服务

更新时间:2022-11-18 19:49:01

您在服务请求中作为参数提供的对象必须标有 [Serializable] 并且基于我之前发布的一些答案,您还需要确保您的自定义对象在构造函数中不包含任何参数.

The objects you provide as arguments as part of the service request must be marked with [Serializable] and based on some of the answers posted before mine you also need to make sure your custom object does not contain any parameters in the constructor.

还要记住,您在类中拥有的任何逻辑都不会在客户端创建的代理类中创建.您将在客户端看到的只是默认构造函数和属性.因此,如果您向自定义对象添加方法,请记住客户端将看不到它们或无法使用它们.

Also keep in mind any logic you have inside your class will not get created in the proxy class that gets created on the client side. All you will see on the client side is a default constructor and properties. So if you add methods to your custom objects keep in mind that the client will not see them or be able to use them.

同样的事情适用于您可能放入任何属性的任何逻辑.

Same thing goes for any logic you might put into any of the properties.

示例

[Serializable]
public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
}