Search code examples
c#xamarincrossover

Xamarin Forms asmx webservice multiple calls


in my Project i call a Webservice like this:

HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("**********");
req.Method = "POST";
req.ContentType = "application/json";

byte[] postDataAsBytesS = Encoding.UTF8.GetBytes(mobileJSON);
Stream postStreamS = req.GetRequestStream();
postStreamS.Write(postDataAsBytesS, 0, postDataAsBytesS.Length);
postStreamS.Flush();
postStreamS.Dispose();

WebResponse resS = req.GetResponse();
postStreamS = resS.GetResponseStream();
StreamReader srS = new StreamReader(postStreamS);

string responseFromServerS = srS.ReadToEnd();

public static class ExtensionsMethods
    {
        public static WebResponse GetResponse(this WebRequest request)
        {
            ManualResetEvent evt = new ManualResetEvent(false);
            WebResponse response = null;
            request.BeginGetResponse((IAsyncResult ar) => {
                response = request.EndGetResponse(ar);
                evt.Set();
            }, null);
            evt.WaitOne();
            return response as WebResponse;
        }

        public static Stream GetRequestStream(this WebRequest request)
        {
            ManualResetEvent evt = new ManualResetEvent(false);
            Stream requestStream = null;
            request.BeginGetRequestStream((IAsyncResult ar) => {
                requestStream = request.EndGetRequestStream(ar);
                evt.Set();
            }, null);
            evt.WaitOne();
            return requestStream;
        }

    }

When i call the above Reqeust 2 times at the same time, i get an error from the webservice.

I get following error:

{"Message":"Column \u0027*****\u0027 doesn't exist in the table.","StackTrace":" in System.Data.DataRow.GetDataColumn(String columnName)\r\n in System.Data.DataRow.get_Item(String columnName)\r\n in webserviceDWA.syncAndroidDWA.GetDWAPDFkategoriezuordnung(dwamobile[] mobile)","ExceptionType":"System.ArgumentException"}

But if i do the request only for 1 time, i get no error.

Can you help me?

Thanks.


Solution

  • I solved the problem. I set the setting "Maximum number of work processes" of the application pool to 100.