WCFを使用して別のアプリケーションからオブジェクトを取得しようとしています。組み込みクラスでは正常に動作しますが、WCF操作からカスタムインターフェイスタイプを返そうとすると、私はprobemsを実行します。WCFサービスで複雑なカスタムインターフェイスタイプを公開する際の問題
両方のアプリケーションに別々にインターフェイスを含めるか、共有アセンブリとして指定するかにかかわらず、同じ結果が得られます。「パイプからの読み取りエラー:認識できないエラー109」というメッセージのCommunicationExceptionが発生します。
インターフェースは次のようになります。
public partial class MainWindow : Window {
private Base fb;
private ServiceHost host;
public MainWindow() {
InitializeComponent();
fb = new Base();
host = new ServiceHost(fb, new Uri[] { new Uri("net.pipe://localhost") });
host.AddServiceEndpoint(typeof(IBase), new NetNamedPipeBinding(),
"PipeReverse");
host.Open();
}
private void Window_Closing(object sender, CancelEventArgs e) {
host.Close();
}
}
そして、ここでは、インターフェイスの私の実装です:
[ServiceContract]
public interface IBase {
int IntTest {
[OperationContract]
get;
}
String StringTest {
[OperationContract]
get;
}
IOther OtherTest {
[OperationContract]
get;
}
}
[ServiceContract]
public interface IOther {
String StringTest {
[OperationContract]
get;
}
}
私のサーバーは、このようになります
[Serializable]
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class Base : MarshalByRefObject, IBase {
public int IntTest {
get { return 4; }
}
public string StringTest {
get { return "A string from Base"; }
}
public IOther OtherTest {
get { return new Other(); }
}
}
[Serializable]
[DataContract]
public class Other : MarshalByRefObject, IOther {
[DataMember]
public string StringTest {
get { return "A string from Other"; }
}
}
クライアントは次のようになりますこれは:
public partial class Form1 : Form {
IBase obj;
public Form1() {
InitializeComponent();
ChannelFactory<IBase> pipeFactory = new ChannelFactory<IBase>(
new NetNamedPipeBinding(), new EndpointAddress(
"net.pipe://localhost/PipeReverse"));
obj = pipeFactory.CreateChannel();
}
private void button2_Click(object sender, EventArgs e) {
Console.WriteLine("Returns: " + obj.StringTest + " " +
obj.StringTest.Length);
Console.WriteLine("Returns: " + obj.IntTest);
Console.WriteLine(obj.OtherTest);
}
}
すべてがこのラインを除いて魔法のように動作します:
Console.WriteLine(obj.OtherTest);
それは私にメッセージしてて、CommunicationExceptionを与える「:認識されないエラー109パイプからの読み取りエラーが発生しました」。限り、私はそれが故障状態のために壊れたパイプだと言うことができますが、私は理由を理解することはできません、またはより重要な方法を修正する。何か案は?
上記のコードでは何も設定されていないため、トレースを有効にする方法がわかりません。それ以外の場合は、それも含めました。
私のマシンでこのコードを実行しました。一方、IntTestメソッドとStringTestメソッドではエラーは返されませんが、データもありません。他の何かが間違っている可能性があります。 –