2

WCF Rest サービスを作成しました。クライアントから(つまり、Androidモバイルから)同じリクエストを継続的にヒットしている場合、異なるスレッドを使用しており、thread.sleepも機能していません。

私のコードは以下のようです..

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
    public class Service1 : IService1
    {
      [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "VerifyLogin")]
        public bool VerifyLogin(Login loginCred)
        {
            bool res = false;
            string strThreadPrint= "";
            try
            {
               strThreadPrint= Thread.CurrentThread.ManagedThreadId.ToString() + "  time at : "+DateTime.Now;
               Thread.Sleep(5000); 
               dbcon = new DBConnection();
//for testing here i am throwing an exception so that its going to catch block and responce sent back to client with exception details as shown in catch block.
               dbcon.VerifyLogin(loginCred.Username.Trim(), loginCred.Password.Trim()); 
            }
            catch (Exception sqlex)
            {
                objErrorClass = new ErrorClass("Login class", sqlex.Message + " --- " + strThreadPrint, "CNMK");
                throw new WebFaultException<ErrorClass>(objErrorClass, System.Net.HttpStatusCode.BadRequest);

            }
        }
    }

次のフィドラーを使用してリクエストを送信するとき Requestbody {"Username":"13","Password":"dgdf"}

その時、私はJson形式のように応答を得ています

Response from service:

{"ErrorDesc":"login failed --- 33 time at :09/04/2013 12:31:30"}
{"ErrorDesc":"login failed --- 35 time at :09/04/2013 12:31:30"}
{"ErrorDesc":"login failed --- 41 time at :09/04/2013 12:31:30"}
{"ErrorDesc":"login failed --- 45 time at :09/04/2013 12:31:30"}

インスタンス モードと同時実行モードは、wcf レストフル サービスでは機能しませんか???? または、コードで何か間違っていますか?? 私を助けてください

4

1 に答える 1