WCF를 사용하여 다른 응용 프로그램에서 개체를 가져 오려고합니다. 내장 된 클래스를 사용하면 잘 작동하지만 WCF 작업에서 사용자 지정 인터페이스 유형을 반환 할 때 probems로 실행됩니다.WCF 서비스에서 사용자 지정 복합 인터페이스 형식 노출 문제
두 응용 프로그램에서 인터페이스를 별도로 포함하거나 공유 어셈블리로 지정하면 동일한 결과가 나타납니다. "파이프에서 읽는 중 오류가 발생했습니다 : 인식 할 수없는 오류 109"라는 메시지가있는 CommunicationException이 발생합니다.
인터페이스는 다음과 같습니다
내 서버는 다음과 같습니다[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 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();
}
}
그리고 인터페이스의 내 구현은 this :
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) 파이프에서 읽기 오류가 발생했습니다." 제가 아는 한 그것은 오류가있는 상태로 인해 깨진 파이프라고 말할 수 있습니다. 그러나 왜 더 중요한지 어떻게 해결해야하는지 알 수 없습니다. 어떤 아이디어?
위의 코드에서 everthing이 수행되므로 설정 파일이 없으므로 추적을 설정하는 방법을 알지 못합니다. 그렇지 않으면 내가 포함했을 것입니다.
내 컴퓨터에서이 코드를 실행했습니다. 반면, IntTest 및 StringTest 메서드에 대해 반환 된 오류가 없으며 데이터도 없습니다. 뭔가 잘못되었을 수 있습니다. –