5

そこで、クライアント/サーバー WCF を作成しました。私が望むのは、このクライアントからサーバーにメッセージを送信し、何らかの理由で接続が切断されたときです。たとえば、クライアントがシャットダウンした場合、このクライアントが再び利用可能になったときにどのように応答を取得できますか?

クライアントとサーバーの間にセッションなどを設定することは可能ですか?

私のクライアントコードは次のとおりです。

private static void Main(string[] args)
{
    var client = new FlipCaseServiceClient("ReliableMessageService");
    var sd = new StringData { FirstName = "Turgut", LastName = "Kançeltik" };

    var fullName = client.GetFullName(ref sd);

    Console.WriteLine(fullName);
}

私のサーバーコードは次のとおりです。

[DeliveryRequirements(RequireOrderedDelivery = true)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Single)]
public class FlipCaseService : IFlipCaseService
{
    public string GetFullName(ref StringData stringData)
    {
        var fullName = $"{stringData.FirstName} {stringData.LastName}";

        stringData.FullName = fullName;
        return fullName;
    }
}

サーバー構成の要約:

<service behaviorConfiguration="ServiceBehaviorMetaData" name="FlipCaseService.FlipCaseService" >
  <endpoint name="ReliableMessageService" address="flipcase/wsAddress" binding="wsHttpBinding" bindingConfiguration="BindingReliableMessaging" contract="FlipCaseService.IFlipCaseService" >
     <identity>
        <dns value="localhost" />
     </identity>
  </endpoint>
</service>

<bindings>
  <wsHttpBinding>
    <binding name="BindingReliableMessaging">
      <reliableSession enabled="true" inactivityTimeout="00:10:00"/>
    </binding>
  </wsHttpBinding>      
</bindings>

<behavior name="ServiceBehaviorMetaData">
  <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8080/flipcase/metadata" />
  <serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
4

1 に答える 1