WCF (Silverlight) 双工 - 未命中服务器

发布于 2024-08-24 01:03:06 字数 6053 浏览 6 评论 0 原文

我在 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”> > > <服务> <服务行为配置=“DuplexServerBehavior”名称=“DuplexServer”> <端点地址=“”绑定=“wsDualHttpBinding”契约=“DuplexServer”/> /> <端点地址=“mex”绑定=“mexHttpBinding”合约=“IMetadataExchange”/> />

我在客户端应用程序中设置了一个 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 请求 - 我假设这些是轮询请求。

初始双工请求:

POST http://localhost/CTC.Test.WCF.Server/DuplexServer .svc HTTP/1.1 接受:/ 内容长度:665 内容类型:application/soap+xml;字符集=utf-8 UA-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.0.30618) 主机:cotocovista4.cotoco.local 连接:保持活动状态 编译指示:无缓存

urn:IDuplexServer/SendEchohttp://docs.oasis-open.org/ws-rx/wsmc/200702/anonymous?id=ae3e3139-0df8-41eb-97db-69c2c48782b743f9e320- cde3-4e21-a748-e5b29c10ee25 s:mustUnderstand="1">http://cotocovista4.cotoco.local/CTC.Test.WCF.Server/DuplexServer.svc消息!;

后续双工请求:

POST http://localhost/CTC.Test.WCF.Server/DuplexServer .svc HTTP/1.1 接受:/ 内容长度:588 内容类型:application/soap+xml;字符集=utf-8 UA-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.0.30618) 主机:cotocovista4.cotoco.local 连接:保持活动状态 编译指示:无缓存

http://docs.oasis-open.org/ws-rx/wsmc/200702/MakeConnection s:mustUnderstand="1">http://cotocovista4.cotoco.local/CTC.Test.WCF.Server/DuplexServer.svc 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;

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

问候

Tris

更新:我尝试在以下项目类型中重新创建此问题:WCF 应用程序、Web 应用程序、Web项目。我已经成功地实现了使用 WCF 消息作为双工参数的 MS 示例,没有出现任何问题,但我一直在寻找一种使用 WSDL 组装双工 Web 服务的快速方法。

I have created a web application with a Silverlight project embedded in it, using VS 2008 SP 1, and the Silverlight 3 tools, on Vista and Windows 7.

The duplex service code:

    [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);
}

The duplex config section:

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="DuplexServerBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="DuplexServerBehavior" name="DuplexServer">
<endpoint address="" binding="wsDualHttpBinding" contract="DuplexServer" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>

I have setup a Duplex service in the client application as follows:

        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);

I have used a Simplex service in tandem with this, and calls to the Simplex service hit the breakpoints setup on the server and i can step through.

Calls to the Duplex service do not hit the breakpoints, although no error is raised on the client. If i inspect the HTTP traffic with Fiddler, i can see hundreds of 202 requests being fired after the initial request - i assume these are the polling requests.

Initial Duplex Request:

POST http://localhost/CTC.Test.WCF.Server/DuplexServer.svc HTTP/1.1
Accept: /
Content-Length: 665
Content-Type: application/soap+xml; charset=utf-8
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; 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)
Host: cotocovista4.cotoco.local
Connection: Keep-Alive
Pragma: no-cache

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

Subsequent Duplex Requests:

POST http://localhost/CTC.Test.WCF.Server/DuplexServer.svc HTTP/1.1
Accept: /
Content-Length: 588
Content-Type: application/soap+xml; charset=utf-8
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; 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)
Host: cotocovista4.cotoco.local
Connection: Keep-Alive
Pragma: no-cache

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

Does anyone know why this would happen, i thought I'd finally sussed the last problem when it stopped throwing connection exceptions....

Regards

Tris

Update: I have tried recreating this in the following project types: WCF Application, Web Application, Web Project. I have succeeded in implementing the MS Example that uses WCF Message's for the Duplex parameters without problem, but i was looking for a rapid way of assembling duplex web services using WSDL.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

束缚m 2024-08-31 01:03:06

所以 - 我最终设法使用以下 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 却不能,那将非常有帮助。 :)

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

问候

Tristan

So - i managed to finally get it working using the following web config section, and adjusting the client side accordingly:

<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>

If anyone can explain why this worked, but using wsDualHttpBinding did not, that would be really helpful. :)

(Also - why is that displayed in a code block? :/ )

Regards

Tristan

浮华 2024-08-31 01:03:06

您是否知道调用是否确实已通过,而只是没有达到断点? (您可以通过插入一些其他副作用来测试这一点,例如记录到文本文件或类似的东西。)我问这个是因为我过去遇到过完全相同的问题,其中托管 WCF 双工服务上的断点即使正在进行调用,IIS 内的内容也不会受到攻击。我最终不得不切换到自托管服务来解决这个问题。我将此作为 MS 的错误提交,他们表示该问题将在 .NET 4.0/VS2010/Silverlight 4.0 时间范围内得到解决。我会发布链接等,但现在找不到它们。

如果这是您的一个选择,并且问题只是未命中断点,我最好的建议是要么迁移到 VS2010,要么迁移到自托管服务。

Do you know if the calls are actually getting through, and just not hitting your breakpoints? (You can test for this by inserting some other side effects, such as logging to a text file or something like that.) I ask this because I've run into exactly the same problem in the past, where breakpoints on WCF duplex services hosted within IIS aren't hit, even though the calls were getting made. I ended up having to switch to a self-hosted service to get around the problem. I filed this as a bug at MS, and they've indicated that it will be resolved in the .NET 4.0/VS2010/Silverlight 4.0 timeframe. I'd post the links, etc., but I can't find them right now.

My best suggestion, if this is an option for you, and if the problem is just that the breakpoints aren't getting hit, is either to move to VS2010, or move to a self-hosted service.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文