我创建了 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 RESTful 服务????还是我在我的代码中做错了什么?请帮我