gpt4 book ai didi

c# - WCF (Silverlight) Duplex - 未访问服务器

转载 作者:太空宇宙 更新时间:2023-11-03 14:32:04 25 4
gpt4 key购买 nike

我在 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);
}

双工配置部分:

<系统.服务模型> <行为> <服务行为> <行为名称="DuplexServerBehavior"> <服务>

我在客户端应用程序中设置了一个 Duplex 服务,如下所示:

        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 请求 - 我假设这些是轮询请求。

初始双工请求:

发布http://localhost/CTC.Test.WCF.Server/DuplexServer.svc HTTP/1.1接受:/内容长度:665内容类型:application/soap+xml;字符集=utf-8UA-CPU:x86接受编码:gzip、deflate用户代理: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.5.30729;.净 CLR 3.0.30618)主机:cotocovista4.cotoco.local连接:保持事件用法:无缓存

urn:IDuplexServer/SendEcho 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:To></s:Header><s:Body><SendEcho><message>Message!</message></SendEcho></s:Body></s:Envelope&gt ;

后续双工请求:

发布http://localhost/CTC.Test.WCF.Server/DuplexServer.svc HTTP/1.1接受:/内容长度:588内容类型:application/soap+xml;字符集=utf-8UA-CPU:x86接受编码:gzip、deflate用户代理: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.5.30729;.净 CLR 3.0.30618)主机:cotocovista4.cotoco.local连接:保持事件用法:无缓存

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"> http://docs.oasis-open.org/ws-rx/wsmc/200702/anonymous?id=ae3e3139-0df8-41eb-97db-69c2c48782b7</wsmc:Address></wsmc:MakeConnection></s:Body></s:Envelope&gt ;

有谁知道为什么会发生这种情况,我想当它停止抛出连接异常时我终于解决了最后一个问题....

问候

三聚体

更新:我尝试在以下项目类型中重新创建它:WCF 应用程序、Web 应用程序、Web 项目。我已经成功地实现了使用 WCF 消息作为双工参数的 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 却行不通,那将非常有帮助。 :)

(另外 - 为什么它显示在代码块中?:/)

问候

特里斯坦

关于c# - WCF (Silverlight) Duplex - 未访问服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2380539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com