我正在构建一个WPF 3.5桌面应用程序,它有一个自我托管的WCF服务。
该服务有一个PollingDuplexHttpBinding端点,定义如下:
public static void StartService()
{
var selfHost = new ServiceHost(Singleton, new Uri("http://localhost:1155/"));
selfHost.AddServiceEndpoint(
typeof(IMyService),
new PollingDuplexHttpBinding(PollingDuplexMode.MultipleMessagesPerPoll) {ReceiveTimeout = new TimeSpan(1,0,0,0)},
"MyService"
);
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
selfHost.AddServiceEndpoint(typeof(IPolicyRetriever), new WebHttpBinding(), "").Behaviors.Add(new WebHttpBehavior());
selfHost.Open();
}注意: IPolicyRetriever是一个使我能够定义策略文件的服务。
这是可行的,我可以在我的客户端Silverlight应用程序中看到我的服务。然后,在Silverlight代码中创建对代理的引用,如下所示:
EndpointAddress address = new EndpointAddress("http://localhost:1155/MyService");
PollingDuplexHttpBinding binding = new PollingDuplexHttpBinding(PollingDuplexMode.MultipleMessagesPerPoll);
binding.ReceiveTimeout = new TimeSpan(1, 0, 0, 0);
_proxy = new MyServiceClient(binding, address);
_proxy.ReceiveReceived += MessageFromServer;
_proxy.OrderAsync("Test", 4);而且这也很好,沟通也很有效!
但是,如果我把它放在一边(即不要从服务器发送消息)超过1分钟,那么尝试从WPF服务器应用程序向客户端发送一条消息,我会得到如下所示的超时错误:
试图在00:01:00之后发送的IOutputChannel超时。增加传递给调用的超时值,以发送或增加绑定上的SendTimeout值。分配给此操作的时间可能是较长超时的一部分。。
它全部在本地主机上运行,不应该有延迟,更不用说1分钟的延迟了。我不知道为什么,但是这个频道好像关闭了或者消失了什么的.
我还尝试删除绑定上的超时,并得到这样的错误
通信对象System.ServiceModel.Channels.ServiceChannel不能用于通信,因为它已被中止。
我怎么才能找出这里出了什么问题?
发布于 2010-10-19 08:13:44
WPF使用wsDualHttpBinding,Silverlight轮询双工.WPF解决方案很简单;Silverlight需要ServiceHostFactory和更多代码。另外,Silverlight Server从不发送消息,而是客户端轮询服务器并检索其消息。
在PollingDuplexHttpBinding出现了许多问题之后,我决定使用没有MultipleMessagesPerPoll的CustomBinding。
web.config
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="SlApp.Web.DuplexServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="SlApp.Web.DuplexServiceBehavior" name="SlApp.Web.DuplexService">
<endpoint address="WS" binding="wsDualHttpBinding" contract="SlApp.Web.DuplexService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>DuplexService.svc:
<%@ ServiceHost Language="C#" Debug="true" Service="SlApp.Web.DuplexService" Factory="SlApp.Web.DuplexServiceHostFactory" %>DuplexServiceHostFactory.cs:
public class DuplexServiceHostFactory : ServiceHostFactoryBase
{
public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses)
{
return new DuplexServiceHost(baseAddresses);
}
}
class DuplexServiceHost : ServiceHost
{
public DuplexServiceHost(params Uri[] addresses)
{
base.InitializeDescription(typeof(DuplexService), new UriSchemeKeyedCollection(addresses));
}
protected override void InitializeRuntime()
{
PollingDuplexBindingElement pdbe = new PollingDuplexBindingElement()
{
ServerPollTimeout = TimeSpan.FromSeconds(3),
//Duration to wait before the channel is closed due to inactivity
InactivityTimeout = TimeSpan.FromHours(24)
};
this.AddServiceEndpoint(typeof(DuplexService),
new CustomBinding(
pdbe,
new BinaryMessageEncodingBindingElement(),
new HttpTransportBindingElement()), string.Empty);
base.InitializeRuntime();
}
}Silverlight客户端代码:
address = new EndpointAddress("http://localhost:43000/DuplexService.svc");
binding = new CustomBinding(
new PollingDuplexBindingElement(),
new BinaryMessageEncodingBindingElement(),
new HttpTransportBindingElement()
);
proxy = new DuplexServiceClient(binding, address);https://stackoverflow.com/questions/3956248
复制相似问题