2つのクライアントプロキシを呼び出すときに2つのサービス間で変数を共有したい。 2つの異なるクライアント呼び出しで2つのサービス間で変数を共有
は**サーバー**サービス1
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class MyService : IMyService
{
public string SharedValue = string.Empty;
public void SETValue(string inputString)
{
SharedValue = inputString;
}
}
[ServiceContract(SessionMode = SessionMode.Required)]
public interface IMyService
{
[OperationContract(IsOneWay = true)]
void SETValue(string inputString);
}
サービス2
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class MyService2 : MyService, IMyService2
{
public string GETSharedValue()
{
return base.SharedValue; //This value got Empty
}
}
[ServiceContract(SessionMode = SessionMode.Required)]
public interface IMyService2
{
[OperationContract]
string GETSharedValue();
}
I」は、次のように私のサンプルコード(そして、また変数は、セッションごとに共有される必要があります)両方のサービスに 'wsHttpBinding'を使用しています。
**クライアント**
private string sharedValue = string.Empty;
MyServiceReference.MyServiceClient client = null;
MyService2Reference.MyService2Client client2 = null;
public Form1()
{
InitializeComponent();
client = new MyServiceReference.MyServiceClient();
client2 = new MyService2Reference.MyService2Client();
}
private void button1_Click(object sender, EventArgs e)
{
client.SETValue("Hello this is client 1");
sharedValue = client2.GETSharedValue();
lblResult.Text = sharedValue;
}
WCFセッションは通常サービスごとです。非永続である必要がありますか?値が実際に属している「セッション」が何であるかを知るための認証や方法がありますか?それをユーザーIDなどに結びつけることはできますか? – smoksnes
InstanceContextSharingを見ることができます。 https://msdn.microsoft.com/en-us/library/aa354514.aspx – smoksnes
クライアントオブジェクトを一度だけインスタンス化します。いいえ、現在認証を使用していません。認証方法を見つける方法はありますか?返信いただきありがとうございます。私はあなたのリンクを確認します。 – Neo