每当尝试连接到我自己的wcf时,我都会收到超时异常。
这是配置我有:
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MetaBehaviour">
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MetaBehaviour" name="WcfStreaming.LargeDataService">
<clear />
<endpoint address="net.tcp://localhost/LargeData" binding="netTcpBinding"
name="Tcp" contract="WcfStreaming.ILargeDataService" listenUriMode="Explicit" />
<endpoint address="net.tcp://localhost/LargeData/mex" binding="mexTcpBinding"
name="TcpMex" contract="IMetadataExchange" listenUriMode="Explicit" />
<endpoint address="http://localhost/wcfstreaming" binding="basicHttpBinding"
bindingConfiguration="" name="BasicHttp" contract="WcfStreaming.ILargeDataService" />
</service>
</services>
</system.serviceModel>
</configuration>
这里是托管代码:
host = new ServiceHost(typeof(WcfStreaming.LargeDataService),
new Uri[] { HttpUri, TcpUri });
host.Open();
var factory = new ChannelFactory<WcfStreaming.ILargeDataService>(new NetTcpBinding(), new EndpointAddress(TcpUri)); // Hnew NetTcpBinding(), new EndpointAddress(TcpUri));
srvChannel = factory.CreateChannel();
using (OpenFileDialog dlg = new OpenFileDialog())
{
if (dlg.ShowDialog() == DialogResult.OK)
{
Stream str = srvChannel.GetFile(dlg.FileName); //Exception here
StreamReader sr = new StreamReader(str);
string bf = sr.ReadToEnd();
File.WriteAllText(@"C:\test", bf);
}
}
我讨厌:
发送到net.tcp:// localhost / LargeData的此请求操作未在配置的超时(00:01:00)内收到回复。 分配给此操作的时间可能是较长超时的一部分。 这可能是因为服务仍在处理操作,或者因为服务无法发送回复消息。 请考虑增加操作超时(通过将通道/代理强制转换为IContextChannel并设置OperationTimeout属性)并确保该服务能够连接到客户端。