1.)メインメソッドProcessingがあります。これは、文字列を引数として取り、その文字列にはx個のタスクが含まれています。
2.)2つの変数TotalTestsとCurrentTestを使用して、最初のメソッドを追跡する別のメソッドStatusがあります。これは、最初のメソッド(処理)でループ内で毎回変更されます。
3.)複数のクライアントが私のWebサービスと並行して呼び出しを行い、異なるタスクを持つ文字列を渡してProcessingメソッドを呼び出す場合、処理に時間がかかります。その間、クライアントは2番目のスレッドを使用してWebサービスのStatusメソッドを呼び出し、最初のメソッドのステータスを取得します。
4.)ポイント番号3が実行されている場合、すべてのクライアントは、他のクライアント要求と混同されることなく、変数(TotalTests、CurrentTest)を並行して取得することになっています。
5.)以下に提供するコードは、すべてのクライアントを静的にすると、すべてのクライアントの変数の結果が混同されます。変数の静的を削除すると、クライアントはこれら2つの変数のすべての0を取得しているだけで、修正できません。以下のコードをご覧ください。
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class Service1 : IService1
{
public int TotalTests = 0;
public int CurrentTest = 0;
public string Processing(string OriginalXmlString)
{
XmlDocument XmlDoc = new XmlDocument();
XmlDoc.LoadXml(OriginalXmlString);
this.TotalTests = XmlDoc.GetElementsByTagName("TestScenario").Count; //finding the count of total test scenarios in the given xml string
this.CurrentTest = 0;
while(i<10)
{
++this.CurrentTest;
i++;
}
}
public string Status()
{
return (this.TotalTests + ";" + this.CurrentTest);
}
}
サーバー構成
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="true" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
クライアント構成
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="true" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
以下は私のクライアントコードです
class Program
{
static void Main(string[] args)
{
Program prog = new Program();
Thread JavaClientCallThread = new Thread(new ThreadStart(prog.ClientCallThreadRun));
Thread JavaStatusCallThread = new Thread(new ThreadStart(prog.StatusCallThreadRun));
JavaClientCallThread.Start();
JavaStatusCallThread.Start();
}
public void ClientCallThreadRun()
{
XmlDocument doc = new XmlDocument();
doc.Load(@"D:\t72CalculateReasonableWithdrawal_Input.xml");
bool error = false;
Service1Client Client = new Service1Client();
string temp = Client.Processing(doc.OuterXml, ref error);
}
public void StatusCallThreadRun()
{
int i = 0;
Service1Client Client = new Service1Client();
string temp;
while (i < 10)
{
temp = Client.Status();
Thread.Sleep(1500);
Console.WriteLine("TotalTestScenarios;CurrentTestCase = {0}", temp);
i++;
}
}
}
誰か助けてくれませんか。