每当试图连接到我的selfhosted wcf时,我会收到一个超时异常。自我托管wcf与nettcp异常
这是我的配置有:
<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属性),并确保服务能够连接到客户端。
尝试在服务器上启用跟踪,您可能会在跟踪中获得比客户端更好的异常。 – carlosfigueira
好吧,你似乎在发送大量的数据,并且你的命名导致你相信你可能也想使用流式处理....也许超时时间太短了 - 你是否尝试增加例如超时3分钟(而不是1)? –
我注意到,在VS下运行很好:内置的wcf客户端运行在.../mex上。那么我应该手动添加mex端点到servicehost吗? – Nickolodeon