所以我创建了客户端/服务器 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>