我开发了一个简单的 Windows 窗体应用程序,在其中托管 NetNamedPipeBinding 服务,并且同一应用程序是尝试调用服务中的函数的客户端,但我收到此错误:
发送到 net.pipe://service1/ 的此请求操作在配置的超时 (00:01:00) 内未收到回复。分配给此操作的时间可能是较长超时的一部分。这可能是因为服务仍在处理操作,或者因为服务无法发送回复消息。请考虑增加操作超时(通过将通道/代理转换为 IContextChannel 并设置 OperationTimeout 属性)并确保服务能够连接到客户端。
这是我的服务:
namespace WcfServiceExample
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string SayHello();
}
public class Service1 : IService1
{
public string SayHello()
{
return "Hello from " + Dns.GetHostName() + " !!";
}
}
}
这是我的 app.config(在我的 Windows 窗体应用程序中):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<!-- CLIENT & SERVER BINDINGS -->
<bindings>
<netNamedPipeBinding>
<binding name="NamedPipeBinding">
<security mode="None" />
</binding>
</netNamedPipeBinding>
</bindings>
<!-- SERVER -->
<services>
<service name="WcfServiceExample.Service1" behaviorConfiguration="svc1behavior">
<endpoint address="net.pipe://service1" binding="netNamedPipeBinding" bindingConfiguration="NamedPipeBinding" name="NamedPipedEndPoint" contract="WcfServiceExample.IService1" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="svc1behavior">
<serviceMetadata />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<!-- CLIENT -->
<client>
<endpoint address="net.pipe://service1" binding="netNamedPipeBinding"
bindingConfiguration="NamedPipeBinding" contract="WcfServiceExample.IService1"
name="NamedPipedClientEndPoint" />
</client>
</system.serviceModel>
</configuration>
这是我的 Windows 窗体应用程序:
namespace ServiceHostAndClientNamedPipesNoProxy
{
public partial class Form1 : Form
{
ServiceHost vHost;
IService1 sc;
public Form1()
{
InitializeComponent();
StartHostService();
StartClient();
}
private void StartHostService()
{
try
{
// Create the service instance
vHost = new ServiceHost(typeof(Service1));
// Open the service
vHost.Open();
}
catch (Exception ex)
{
vHost.Abort();
}
}
private void StartClient()
{
NetNamedPipeBinding binding = new NetNamedPipeBinding("NamedPipeBinding");
ChannelFactory<IService1> cf = new ChannelFactory<IService1>("NamedPipedClientEndPoint");
sc = cf.CreateChannel();
//((IContextChannel)sc).OperationTimeout = new TimeSpan(0, 3, 0);
textBox1.Text = "Connected to " + cf.Endpoint.Address.ToString();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
vHost.Close();
}
private void btnInvokeMethod_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
textBox2.Text = textBox2.Text + System.Environment.NewLine + sc.SayHello();
this.Cursor = Cursors.Default;
}
}
}
请帮忙,我被这个困住了!!!
提前说。