WebClient不支持并发I / O操作。在c#当我打电话给我的wcf服务

时间:2017-09-10 07:48:52

标签: c# wcf webclient

我有一个课程,你可以看到它调用我的服务。

 public class ReceptionService : IReceptionService
        {
            private WebClient ClientRequest;
            private MemoryStream ms;
            private DataContractJsonSerializer serializerToUplaod;
            public string ServiceHostName = "http://Reception" + ServiceServer.ServiceAddress;

            public ReceptionService()
            {
                ClientRequest = new WebClient();
                ms = new MemoryStream();
            }


            public int ValidateAndSubmitReception(NajaResult ReceptionData)
            {
                ClientRequest.Headers["Content-type"] = "application/json";
                serializerToUplaod = new DataContractJsonSerializer(typeof(NajaResult));
                serializerToUplaod.WriteObject(ms, ReceptionData);
                string Result = System.Text.Encoding.UTF8.GetString(ClientRequest.UploadData(ServiceHostName + "/ReceptionService.svc/ValidateAndSubmitReception", "POST", ms.ToArray()));
                return int.Parse(Result.Replace("\"", string.Empty).ToString());
                //return receptionid

            }


            public List<ReceptionView> SearchReceptionView(string receptionId, string organizationid, string automotiveid, string referredid, string organizationuserid, string datestart, string dateend)
            {
                ClientRequest.Headers["Content-type"] = "application/json";
                ClientRequest.Encoding = System.Text.Encoding.UTF8;
                string result = ClientRequest.DownloadString(ServiceHostName + "/ReceptionService.svc/SearchReceptionView/" + receptionId + "/" +
                                                                                                              );
                var javascriptserializer = new JavaScriptSerializer();
                return javascriptserializer.Deserialize<List<ReceptionView>>(result);
            }
    }

但是我得到了这个错误:

 An unhandled exception has occurred. 
       9/10/2017 12:12:22 PM 
       9/10/2017 7:42:22 AM 
       aa5bf89271374f3199c105419ee229c5 
       40394 
       2002 
       0 
       /LM/W3SVC/3/ROOT-1-131494715467654187 
       Full 
       / 
       C:\inetpub\a1New\ 
       aa-APP1 

       6020 
       w3wp.exe 
       IIS APPPOOL\Newa1 
       NotSupportedException 
       WebClient does not support concurrent I/O operations. at System.Net.WebClient.ClearWebClientState() at System.Net.WebClient.DownloadString(Uri address) at UPTO.UI.Services.Service.UserService.GetPermissionByUserId(String UserId) at UPTO.UI.Infrastructure.Security.MyRoleProvider.GetRolesForUser(String UserId) at System.Web.Security.RolePrincipal.IsInRole(String role) at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate) at System.Web.Mvc.AuthorizeAttribute.AuthorizeCore(HttpContextBase httpContext) at System.Web.Mvc.AuthorizeAttribute.OnAuthorization(AuthorizationContext filterContext) at System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__19(AsyncCallback asyncCallback, Object asyncState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TResult](AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) at System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) at System.Web.Mvc.Controller.<BeginExecuteCore>b__1c(AsyncCallback asyncCallback, Object asyncState, ExecuteCoreState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TState](AsyncCallback callback, Object callbackState, BeginInvokeDelegate`1 beginDelegate, EndInvokeVoidDelegate`1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext) at System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TState](AsyncCallback callback, Object callbackState, BeginInvokeDelegate`1 beginDelegate, EndInvokeVoidDelegate`1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext) at System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TState](AsyncCallback callback, Object callbackState, BeginInvokeDelegate`1 beginDelegate, EndInvokeVoidDelegate`1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)  
       https://newa1.moi.ir:443/TestCenters/GasReceptions/PrintReception?ReceptionId=12948 
       /TestCenters/GasReceptions/PrintReception 
       10.138.132.17 
       6726 
       True 
       Forms 
       IIS APPPOOL\Newa1 
       3570 
       IIS APPPOOL\Newa1 
       False 
       at System.Net.WebClient.ClearWebClientState() at System.Net.WebClient.DownloadString(Uri address) at UPTO.UI.Services.Service.UserService.GetPermissionByUserId(String UserId) at UPTO.UI.Infrastructure.Security.MyRoleProvider.GetRolesForUser(String UserId) at System.Web.Security.RolePrincipal.IsInRole(String role) at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate) at System.Web.Mvc.AuthorizeAttribute.AuthorizeCore(HttpContextBase httpContext) at System.Web.Mvc.AuthorizeAttribute.OnAuthorization(AuthorizationContext filterContext) at System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__19(AsyncCallback asyncCallback, Object asyncState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TResult](AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate`1 endDelegate, Object tag, Int32 timeout) at System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) at System.Web.Mvc.Controller.<BeginExecuteCore>b__1c(AsyncCallback asyncCallback, Object asyncState, ExecuteCoreState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TState](AsyncCallback callback, Object callbackState, BeginInvokeDelegate`1 beginDelegate, EndInvokeVoidDelegate`1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext) at System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TState](AsyncCallback callback, Object callbackState, BeginInvokeDelegate`1 beginDelegate, EndInvokeVoidDelegate`1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext) at System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TState](AsyncCallback callback, Object callbackState, BeginInvokeDelegate`1 beginDelegate, EndInvokeVoidDelegate`1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)  

0 个答案:

没有答案