如何让客户端通过网络服务传递我的对象?

发布于 2024-10-02 19:30:36 字数 1100 浏览 0 评论 0原文

抱歉,如果这是一个愚蠢的问题,因为我对 .NET 远程处理和分布式对象有点困惑。

我想编写一个 Web 服务,在其方法之一中,我希望用户将我的对象的实例作为参数传递。这将大大减少参数的数量,并帮助用户更有效地调用该方法。我创建了一些类,但是当将它们分发给客户端时,仅保留类名,所有属性和方法都消失了,就像这样

public class CameraPackages
{
    private readonly List<CameraPackage> _packages;

    public CameraPackages()
    {
        _packages = new List<CameraPackage>();
    }

    public void AddNewCamera(CameraPackage package)
    {
        _packages.Add(package);
    }

    public void RemoveCamera(CameraPackage package)
    {
        if(_packages.Contains(package))
            _packages.Remove(package);
        else
            throw new ArgumentException();
    }
}

:(在Reference.cs中)

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class CameraPackages {
}

我怎样才能允许用户使用我的对象? 太感谢了。

Sorry if this is stupid question, because I'm a bit confused about .NET remoting and distributed object.

I want to write a webservice, and in one of its methods, I want user to pass one my object's instance as parameter. It will greatly reduces number of parameters, and help user call this method more effectively. I create some class, but when distributing them to client, only class name remains, all properties and methods are gone, just like this

public class CameraPackages
{
    private readonly List<CameraPackage> _packages;

    public CameraPackages()
    {
        _packages = new List<CameraPackage>();
    }

    public void AddNewCamera(CameraPackage package)
    {
        _packages.Add(package);
    }

    public void RemoveCamera(CameraPackage package)
    {
        if(_packages.Contains(package))
            _packages.Remove(package);
        else
            throw new ArgumentException();
    }
}

into this: (in Reference.cs)

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class CameraPackages {
}

How can I do to allow user use my object?
Thank you so much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花落人离去 2024-10-09 19:30:36

Web 服务只会序列化公共属性,因此您无法使用 Web 服务(以这种方式)执行此操作。

您将需要管理客户端的对象列表,然后在传输对象(仅具有属性的类)中发送数据。

看看这个。

Web Services will only serialise public properties, so you can't do that (in that way) using web services.

You will need to manage your list of objects client side, then send the data in a transfer object (a class with just properties).

Have a look at this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文