我开发了一个简单的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;
}
}
}
请帮助,我坚持这个!!!。
提前吃完。