0

NetNamedPipeBinding エンドポイントでリッスンする ServiceHost があります。クライアントによって呼び出され、サーバーによって処理される単一のメソッドを持つサービス コントラクト クラスがあります。メソッド (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);
    }
}
4

2 に答える 2

1

ServiceRequestBase を継承するクラスを渡す必要がありますproxy.PipeRequest(this); 。クラスが ServiceRequestBase を継承する場合、シリアライズできない可能性があります。

于 2011-06-30T20:33:19.850 に答える
0

ServiceRequestBase クラスから派生したクラスを (データ コントラクトの一部として) 指定する必要があったことがわかりました。

[DataContract]
[KnownType(typeof(CitrixInfoServiceRequest))]   // added this line
[KnownType(typeof(RegStateServiceRequest))] // added this line
public abstract class ServiceRequestBase
{
    // ...
}
于 2011-08-05T17:43:55.087 に答える