WCF自承载 客户端连接超时问题

wangji666666 2012-02-17 03:08:26
本人刚学WCF,碰到一个问题一直无法解决,问题描述:
新建了一个wcf服务工程,编译成WcfServiceLibrary1.dll,代码没改。设置为调试时不启动服务
新建了自承载应用程序。
代码如下:

private void Form1_Load(object sender, EventArgs e)
{
host = new ServiceHost(typeof(WcfServiceLibrary1.Service1));
host.Open();//启动服务
}

//想在此应用程序中直接调用服务内容
private void button1_Click(object sender, EventArgs e)
{
ChannelFactory<WcfServiceLibrary1.IService1> channel = new ChannelFactory<WcfServiceLibrary1.IService1>(new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:12345/wcfservice"));
client = channel.CreateChannel();
client.GetData(0);//执行到这里就卡住了。错误在下面
}

//该应用程序的app配置文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="WcfServiceLibrary1.Service1Behavior"
name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="NewBinding0"
contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:12345/wcfservice/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceLibrary1.Service1Behavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="NewBinding0" portSharingEnabled="false">
<!--<security mode="None" />-->
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>


错误:发送到 net.tcp://localhost:12345/wcfservice 的请求操作在配置的超时(00:01:00)内未收到回复。分配给该操作的时间可能是更长超时的一部分。这可能由于服务仍在处理操作或服务无法发送回复消息。请考虑增加操作超时(将通道/代理转换为 IContextChannel 并设置 OperationTimeout 属性)并确保服务能够连接到客户端。

请教大家这是什么原因?还有一个小问题,我服务启动后通过IE打开net.tcp://localhost:12345/wcfservice,或者http://localhost:12345/wcfservice,都无法打开,这是为什么?
...全文
263 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
kslynn 2013-11-15
  • 打赏
  • 举报
回复
不知道你的问题解决了没有/ 这种情况是说连线超时了, WCF有一个预设的超时时间, 你把这个时间改大点就行了. 看你的配置文件, 需要把配置文件中binding的 SendTimeOut 设得大一点. 如下, 设成30分钟看看. <binding name="NewBinding0" sendTimeOut="00:30:00" portSharingEnabled="false">
wangji666666 2012-02-20
  • 打赏
  • 举报
回复
有没有做过的人提供点经验啊
wangji666666 2012-02-17
  • 打赏
  • 举报
回复
没人知道吗?

110,568

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧