NetNamedPipeBinding:管道方法中的参数为空

发布于 2024-11-18 02:22:54 字数 1014 浏览 2 评论 0原文

我有一个 ServiceHost 正在侦听 NetNamedPipeBinding 端点。我有一个服务契约类,它有一个方法,由客户端调用并由服务器处理。该方法(我们将其称为 PipeRequest())有一个 Request 参数。在客户端,我填充了这个对象,但当它发送到服务器时它是空的。有什么想法为什么会出现这种情况吗?

_Host = new ServiceHost(typeof(PipeService), new Uri(ServiceRequestRouter.URI));
_Host.AddServiceEndpoint(
    typeof(IPipeService),
    new NetNamedPipeBinding(),
    _PipeName
);
_Host.Open();

[ServiceContract(Namespace = "http://www.example.com/PipeCommunication")]
interface IPipeService
{
    [OperationContract]
    void PipeRequest(ServiceRequestBase request);
}

[DataContract]
[KnownType(typeof(DerivedServiceRequest))]
[KnownType(typeof(SomeEnumType))]
public abstract class ServiceRequestBase
{
    ...

    public void Dispatch(string pPipeName = ServiceRequestRouter.DefaultPipeName)
    {
        EndpointAddress epa = new EndpointAddress(_address_));
        IPipeService proxy = ChannelFactory<IPipeService>.CreateChannel(new NetNamedPipeBinding(), epa);
        proxy.PipeRequest(this);
    }
}

I have a ServiceHost listening on a NetNamedPipeBinding endpoint. I have a service contract class with a single method which is being called by the client and handled by the server. The method (We'll call it PipeRequest()) has a Request parameter. On the client side I populate this object but it's empty by the time it gets sent over to the server. Any ideas why this would be the case?

_Host = new ServiceHost(typeof(PipeService), new Uri(ServiceRequestRouter.URI));
_Host.AddServiceEndpoint(
    typeof(IPipeService),
    new NetNamedPipeBinding(),
    _PipeName
);
_Host.Open();

[ServiceContract(Namespace = "http://www.example.com/PipeCommunication")]
interface IPipeService
{
    [OperationContract]
    void PipeRequest(ServiceRequestBase request);
}

[DataContract]
[KnownType(typeof(DerivedServiceRequest))]
[KnownType(typeof(SomeEnumType))]
public abstract class ServiceRequestBase
{
    ...

    public void Dispatch(string pPipeName = ServiceRequestRouter.DefaultPipeName)
    {
        EndpointAddress epa = new EndpointAddress(_address_));
        IPipeService proxy = ChannelFactory<IPipeService>.CreateChannel(new NetNamedPipeBinding(), epa);
        proxy.PipeRequest(this);
    }
}

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

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

发布评论

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

评论(2

去了角落 2024-11-25 02:22:54

看起来它与 proxy.PipeRequest(this); 有关。
您需要传入一个继承ServiceRequestBase的类,如果您的类确实继承了ServiceRequestBase那么它可能无法序列化。

It look like it has to do with proxy.PipeRequest(this);
You need to pass in a class that inherits ServiceRequestBase, if you class does inherit the ServiceRequestBase then it might not be serializable.

半岛未凉 2024-11-25 02:22:54

事实证明,我必须指定(作为数据协定的一部分)来自 ServiceRequestBase 类的任何派生类。

[DataContract]
[KnownType(typeof(CitrixInfoServiceRequest))]   // added this line
[KnownType(typeof(RegStateServiceRequest))] // added this line
public abstract class ServiceRequestBase
{
    // ...
}

It turns out I had to specify (as part of the data contract) any derived classes from ServiceRequestBase class.

[DataContract]
[KnownType(typeof(CitrixInfoServiceRequest))]   // added this line
[KnownType(typeof(RegStateServiceRequest))] // added this line
public abstract class ServiceRequestBase
{
    // ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文