[英]WCF (Silverlight) Duplex - Not hitting server
我已经在Vista和Windows 7上使用VS 2008 SP 1和Silverlight 3工具创建了一个嵌入了Silverlight项目的Web应用程序。
双工服务代码:
[ServiceContract(Namespace = "cotoco", CallbackContract = typeof(IDuplexClient))]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class DuplexServer
{
private IDuplexClient _client;
private string _message;
private int _messageCounter;
private Timer _timer;
public DuplexServer()
{
}
#region IDuplexServer Members
[OperationContract(IsOneWay = true)]
public void SendEcho(string message)
{
_client = OperationContext.Current.GetCallbackChannel<IDuplexClient>();
_message = message;
_timer = new Timer();
_timer.Interval = 2000;
_timer.Enabled = true;
_timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
_timer.Start();
}
void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
_client.ReturnEcho(string.Format("Duplex Echo {0}: {1}", _messageCounter, _message));
_messageCounter++;
if (_messageCounter > 5)
_timer.Dispose();
}
#endregion
}
[ServiceContract]
public interface IDuplexClient
{
[OperationContract(IsOneWay = true)]
void ReturnEcho(string message);
}
双工配置部分:
<system.serviceModel> <behaviors> <serviceBehaviors> <behavior name =“ DuplexServerBehavior”> <serviceMetadata httpGetEnabled =“ true” /> <serviceDebug includeExceptionDetailInFaults =“ false” /> </ behavior> </ serviceBehaviors> </ behaviors> < serviceHostingEnvironment aspNetCompatibilityEnabled =“ true” /> <服务> <服务behaviorConfiguration =“ DuplexServerBehavior” name =“ DuplexServer”> <端点地址=“” binding =“ wsDualHttpBinding” contract =“ DuplexServer” /> <端点地址=“ mex”绑定=“ mexHttpBinding” contract =“ IMetadataExchange” /> </ service> </ services> </system.serviceModel>
我已经在客户端应用程序中设置了双工服务,如下所示:
Binding svcBinding;
EndpointAddress svcAddress;
svcBinding = new PollingDuplexHttpBinding() { UseTextEncoding = true };
svcAddress = new EndpointAddress("http://localhost/CTC.Test.WCF.Server/DuplexServer.svc");
_duplex = new DuplexServerClient(svcBinding, svcAddress);
我已经与此同时使用了Simplex服务,并且对Simplex服务的调用达到了服务器上的断点设置,我可以逐步进行。
尽管不会在客户端上引发任何错误,但对Duplex服务的调用不会达到断点。 如果我使用Fiddler检查HTTP流量,则可以看到在初始请求之后引发了数百个202个请求-我认为这些是轮询请求。
初始双工请求:
POST http://localhost/CTC.Test.WCF.Server/DuplexServer.svc HTTP / 1.1接受: /内容长度:665内容类型:application / soap + xml; charset = utf-8 UA-CPU:x86接受编码:gzip,压缩用户代理:Mozilla / 4.0(兼容; MSIE 7.0; Windows NT 6.0;(R1 1.6); SLCC1; .NET CLR 2.0.50727; InfoPath。 2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618)主机:cotocovista4.cotoco.local连接:保持活动语法:无缓存
<s:信封xmlns:a =“ http://www.w3.org/2005/08/addressing” xmlns:s =“ http://www.w3.org/2003/05/soap-envelope”> < s:Header> <a:Action s:mustUnderstand =“ 1”> urn:IDuplexServer / SendEcho </ a:Action> <netdx:Duplex xmlns:netdx =“ http://schemas.microsoft.com/2008/04/ netduplex“> <netdx:Address> http://docs.oasis-open.org/ws-rx/wsmc/200702/anonymous?id=ae3e3139-0df8-41eb-97db-69c2c48782b7</netdx:Address><netdx: SessionId> 43f9e320-cde3-4e21-a748-e5b29c10ee25 </ netdx:SessionId> </ netdx:Duplex> <a:To s:mustUnderstand =“ 1”> http://cotocovista4.cotoco.local/CTC.Test.WCF .Server / DuplexServer.svc </ A:向> </ s的:报头> <S:BODY> <SendEcho> <信息>信息</消息> </ SendEcho> </ S:身体> <!/秒:信封&GT ;
随后的双工请求:
POST http://localhost/CTC.Test.WCF.Server/DuplexServer.svc HTTP / 1.1接受: /内容长度:588内容类型:application / soap + xml; charset = utf-8 UA-CPU:x86接受编码:gzip,压缩用户代理:Mozilla / 4.0(兼容; MSIE 7.0; Windows NT 6.0;(R1 1.6); SLCC1; .NET CLR 2.0.50727; InfoPath。 2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618)主机:cotocovista4.cotoco.local连接:保持活动语法:无缓存
<s:信封xmlns:a =“ http://www.w3.org/2005/08/addressing” xmlns:s =“ http://www.w3.org/2003/05/soap-envelope”> < s:Header> <a:Action s:mustUnderstand =“ 1”> http://docs.oasis-open.org/ws-rx/wsmc/200702/MakeConnection</a:Action><a:To s:mustUnderstand =“ 1”> http://cotocovista4.cotoco.local/CTC.Test.WCF.Server/DuplexServer.svc </ a:To> </ s:Header> <s:Body> <wsmc:MakeConnection xmlns:wsmc =“ http://docs.oasis-open.org/ws-rx/wsmc/200702”> <wsmc:地址> http://docs.oasis-open.org/ws-rx/wsmc/200702/匿名? id = ae3e3139-0df8-41eb-97db-69c2c48782b7 </ wsmc:Address> </ wsmc:MakeConnection> </ s:Body> </ s:Envelope&gt ;
有谁知道为什么会这样,我以为我终于在停止引发连接异常时怀疑了最后一个问题。
问候
三
更新:我尝试在以下项目类型中重新创建它:WCF应用程序,Web应用程序,Web项目。 我已经成功实现了将WCF消息用于Duplex参数的MS示例,但没有出现问题,但是我正在寻找一种使用WSDL组装双工Web服务的快速方法。
所以-我设法使用下面的Web配置部分最终使它工作,并相应地调整了客户端:
<system.serviceModel>
<extensions>
<bindingElementExtensions>
<add name="pollingDuplex"
type="System.ServiceModel.Configuration.PollingDuplexElement, System.ServiceModel.PollingDuplex"/>
</bindingElementExtensions>
</extensions>
<bindings>
<customBinding>
<binding name="DuplexConfig">
<binaryMessageEncoding/>
<pollingDuplex maxPendingSessions="2147483647" maxPendingMessagesPerSession="2147483647" inactivityTimeout="02:00:00" serverPollTimeout="00:05:00"/>
<httpTransport/>
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="CTC.Test.WCF.Server.DuplexServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentSessions="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="CTC.Test.WCF.Server.DuplexServiceBehavior" name="CTC.Test.WCF.Server.DuplexService">
<endpoint address="" binding="customBinding" bindingConfiguration="DuplexConfig" contract="CTC.Test.WCF.Server.IDuplexService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
如果有人可以解释为什么这样做有效,但是使用wsDualHttpBinding却没有效果,那将非常有帮助。 :)
(而且-为什么在代码块中显示该内容?:/)
问候
特里斯坦
您知道呼叫是否真的通过了,而没有达到断点吗? (您可以通过插入一些其他副作用来进行测试,例如,记录到文本文件之类的东西。)我之所以这样问,是因为过去我遇到了完全相同的问题,在该问题上托管了WCF双工服务的断点即使调用已完成,在IIS中也不会受到攻击。 我最终不得不切换到自托管服务来解决该问题。 我将其作为MS的错误提交,他们表示将在.NET 4.0 / VS2010 / Silverlight 4.0时间段内解决。 我会发布链接等,但现在找不到它们。
我最好的建议是,如果这是您的一个选择,并且问题仅仅是断点没有受到影响,则是迁移到VS2010,还是迁移到自托管服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.