2

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" /> <services> <service behaviorConfiguration="DuplexServerBehavior" name="DuplexServer"> <endpoint address="" binding="wsDualHttpBinding" contract="DuplexServer" /> <endpoint address="mex" バインディング="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> </system.serviceModel>

次のように、クライアント アプリケーションで 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);

これと並行してシンプレックス サービスを使用しており、シンプレックス サービスへの呼び出しがサーバー上のブレークポイント設定にヒットし、ステップ スルーできます。

Duplex サービスへの呼び出しはブレークポイントに到達しませんが、クライアントでエラーは発生しません。Fiddler で HTTP トラフィックを調べると、最初のリクエストの後に何百もの 202 リクエストが発生していることがわかります。これらはポーリング リクエストだと思います。

最初のデュプレックス要求:

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 (互換; MSIE 7.0; Windows NT 6.0; (R1 1.6); SL​​CC1; .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 接続: Keep-Alive プラグマ: no-cache

<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:アドレス> http://docs.oasis-open.org/ws-rx/wsmc/200702/anonymous?id=ae3e3139-0df8-41eb-97db-69c2c48782b7</netdx:アドレス><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:封筒> ;

後続の二重リクエスト:

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 (互換; MSIE 7.0; Windows NT 6.0; (R1 1.6); SL​​CC1; .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 接続: Keep-Alive プラグマ: no-cache

<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/anonymous? id=ae3e3139-0df8-41eb-97db-69c2c48782b7</wsmc:Address></wsmc:MakeConnection></s:Body></s:封筒> ;

なぜこれが起こるのか誰か知っていますか?接続例外のスローを停止したときに、最後の問題を最終的に解決したと思いました....

よろしく

トリス

更新: 次のプロジェクト タイプでこれを再作成しようとしました: WCF アプリケーション、Web アプリケーション、Web プロジェクト。Duplex パラメーターに WCF メッセージを使用する MS Example を問題なく実装することに成功しましたが、WSDL を使用して二重 Web サービスを迅速に組み立てる方法を探していました。

4

2 に答える 2

1

そのため、次の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 を使用しても機能しなかった場合、それは非常に役立ちます。:)

(また、なぜそれがコード ブロックに表示されるのですか? :/)

よろしく

トリスタン

于 2010-03-09T12:21:06.083 に答える
0

呼び出しが実際に通過していて、ブレークポイントに達していないだけかどうか知っていますか? (テキスト ファイルなどへのログ記録など、他の副作用を挿入することで、これをテストできます。) 私がこれを尋ねるのは、過去にまったく同じ問題に遭遇したためです。WCF 二重サービスのブレークポイントがホストされていました。呼び出しが行われていたとしても、IIS 内ではヒットしません。問題を回避するために、自己ホスト型サービスに切り替える必要がありました。これをバグとして MS に報告したところ、.NET 4.0/VS2010/Silverlight 4.0 のタイムフレームで解決されることが示されました。リンクなどを掲載したいのですが、今のところ見つかりません。

これが選択肢であり、問​​題がブレークポイントに到達していないというだけの場合は、VS2010 に移行するか、自己ホスト型サービスに移行することをお勧めします。

于 2010-03-04T16:16:16.710 に答える