我已經實現了我的第一個WCF應用程序。 我需要一個方法IConsoleData GetData();
我收到CommunicationException "There was an error reading from the pipe: The channel was closed. (109, 0x6d)."
客戶端。我的第一個WCF服務器 - 適用於「字符串」但不適用於自定義界面?
當我更換IConsoleData GetData();
到string GetData();
申請成爲有功能。
我應該如何修復代碼使用IConsoleData GetData()
?
服務器:
//public interface IConsoleData
//{
// double GetCurrentIndicator();
//}
//public class IConsoleDataImpl : IConsoleData
//{
// public double GetCurrentIndicator()
// {
// return 22;
// }
//}
[ServiceContract]
public interface IMBClientConsole
{
[OperationContract]
//IConsoleData GetData();
string GetData();
}
public class MBClientConsole : IMBClientConsole
{
//public IConsoleData GetData()
//{
// return new IConsoleDataImpl();
//}
public string GetData()
{
//return new IConsoleDataImpl();
return "hello";
}
}
class Log
{
private ServiceHost _host;
public void initialize()
{
_host = new ServiceHost(typeof (MBClientConsole),
new Uri[]
{
new Uri("net.pipe://localhost")
});
_host.AddServiceEndpoint(typeof(IMBClientConsole),
new NetNamedPipeBinding(),
"PipeReverse");
_host.Open();
System.Threading.Thread.Sleep(1000000);
// TODO: host.Close();
}
}
客戶:
//public interface IConsoleData
//{
// double GetCurrentIndicator();
//}
[ServiceContract]
public interface IMBClientConsole
{
[OperationContract]
//IConsoleData GetData();
string GetData();
}
class Program
{
static void Main(string[] args)
{
ChannelFactory<IMBClientConsole> pipeFactory =
new ChannelFactory<IMBClientConsole>(
new NetNamedPipeBinding(),
new EndpointAddress(
"net.pipe://localhost/PipeReverse"));
IMBClientConsole pipeProxy =
pipeFactory.CreateChannel();
while (true)
{
string str = Console.ReadLine();
Console.WriteLine("pipe: " +
//pipeProxy.GetData().GetCurrentIndicator());
pipeProxy.GetData());
}
}
}
您報告的錯誤似乎與渠道可用性有關,而非DataContract問題。如果讓GetData返回一個tyoe對象,它將如何工作:IConsoleDataImpl Ah,P.S.刪除第一個我只是叫它ConsoleData如果是一個類;-) –
對於混亂對不起,實際上我很少使用'我'因爲我在Java上編程主要是'我'不是很受歡迎 – javapowered