none
Silverlight WCF service intermitten error RRS feed

  • Question

  • I've been struggling to isolate what exactly is happening with our application.  We have some silverlight controls that have been added into our main web application for dashboard viewing that update via individual timers and hit a silverlight enabled wcf web service that is also a part of the main web application (not a seperate service).  Intermittenly, the dashboards with silverlight controls on them stop working and throw and error (401 error).  This error happens usually between 20min - 2hours of opening the dashes, but it always happens. 

    I'm testing currently with two dashboards open with about 12 silverlight grids on them, so in total that's 24 calls every 10 seconds to the service and the data coming back is very small (4 rows - 5 columns).

    Another odd and maybe not related to this is that if I open say 4 of these dashboards (24 SL controls then total - 6 to a window), IE crashes and tries to reload them.  Not sure what's going on there...too many calls to the service at once??  

    I've been reading a ton of stuff and trying all kinds of things and started with the "timeout" settings in the config files and added them in to see if it would help, maxconnection setting added in, closing out proxy or service calls, etc....nothing works.  Below is the basics of what I have and an XML clip from the Service Trace Viewer

    Hopefully the below helps.....I'm throughly out of ideas here on what is happening.  Thanks for any help

    private static double UpdateFrequency = 10;
    Public MainPage()
    {
    	    //Get grid data
                loadupData();
                // timer initialization 
                this.timer = new DispatcherTimer();
                this.timer.Interval = this.refreshInterval;
                this.timer.Tick += new EventHandler(timer_Tick);
                timer.Start();
    }
    private void loadupData()
            {
                try
                {
    		//If I call this service the memory footprint continues to climb, EVEN if I return a NULL set of data
                          MainDataClient client = WCFHelper.CreateService<MainDataClient>("../MainData.svc"); 
                          client.DataMemberListCompleted += new EventHandler<DataMemberListCompletedEventArgs>(client_DMembersListCompleted);
                          client.DataMemberListAsync(DMid, WhichOne);
                }
                catch (Exception r)
                {
                        MessageBox.Show("Error occured loading the data: " + r.Message);
                }
    }
    void timer_Tick(object sender, EventArgs e)
            {
                    //Get new data
                    loadupData();
             }
    //etc..
    ///...do stuff here with returned dataTable and then load grid
    //Service//
    using System;
    using System.Linq;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    using System.Collections.Generic;
    using System.Data;
    using System.Configuration;
    using System.Data.SqlClient;
    namespace CVR_New
    {
        [ServiceContract(Namespace = "")]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
        public class MainData
        {
            Code.DAL.ErrorHandler err = new Code.DAL.ErrorHandler();
            Code.BLL.CVRFunctions functions = new Code.BLL.CVRFunctions();
            [OperationContract]
            public List<DMembers> DataMemberList(Int32 DMid, Int32 WhichTable)
            {
                var connA = ConfigurationManager.ConnectionStrings["aPrimary"].ConnectionString;
                var connB = ConfigurationManager.ConnectionStrings["aSecondary"].ConnectionString;
                var dmList = new List<DMembers>();
               
                SqlConnection connDM = new SqlConnection();
                //Check for valid main connection
                try
                {
                    connDM.ConnectionString = connA;
                    connDM.Open();
                }
                catch (SqlException sqlex)
                {
                    err.ManageError(sqlex, System.Reflection.MethodBase.GetCurrentMethod().Name);
                    try
                    {
                        connDM.ConnectionString = connB;
                        connDM.Open();
                    }
                    catch (Exception ex)
                    {
                        err.ManageError(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
                    }
                }
                    string sql = string.Empty;
                    if (WhichTable != 0)
                    {
                       //sql = "inline sql here".....
                    }
                    else
                    {
                       
                        //sql = "inline sql here".....
                    }
                    using (SqlCommand cmd = new SqlCommand(sql, connDM))
                    {
                        cmd.Parameters.Add("@DMID", SqlDbType.Int).Value = dmid;
                        SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                        if (dr != null)
                            while (dr.Read())
                            {
                                var datamembers = new DMembers
                                {
                                    //list out all variables from DMembers class
                                    DMID = dr.GetInt32(0),
                                    DID = dr.GetInt32(1),
                                    DSID = dr.GetInt32(2),
                                    DSOID = dr.GetInt32(3),
                                    OSQL = dr.GetString(4),
                                    TCN = dr.GetString(5),
                                    Txt = dr.GetString(6),
                                    Style = dr.GetString(7),
                                    YThr = dr.GetString(8),
                                    YStyle = dr.GetString(9),
                                    RThr = dr.GetString(10),
                                    RStyle = dr.GetString(11),
                                    ConnStr = dr.GetString(12),
                                    BackupStr = dr.GetString(13)
                                };
                                dmList.Add(datamembers);
                            }
                        return dmList;
                    }
            }
       }
    }
    void client_DMembersListCompleted(object sender, DataMemberListCompletedEventArgs e)
            {
                if (e.Error != null)
                {
                    if (e.Error is FaultException<ExceptionDetail>)
                    {
                            ExceptionDetail exceptDetail = ((FaultException<ExceptionDetail>)e.Error).Detail;
                            HtmlPage.Window.Alert("Error: " + exceptDetail.Message + "\n" + exceptDetail.StackTrace.ToString());
                    }
                }
                try
                {
                    if (Convert.ToInt32(e.Result.Count) != 0)
                    {
                        string tmpsql = (e.Result[0].ObjSQL.ToString());
                        int DSID = ((int)e.Result[0].DID);
                        YSs = (e.Result[0].YStyle.ToString());
                        YTs = (e.Result[0].YThr.ToString());
                        RSs = (e.Result[0].RStyle.ToString());
                        RTs = (e.Result[0].RThr.ToString());
                        CHNs = (e.Result[0].TCN.ToString());
                        mStyles = (e.Result[0].Style.ToString());
                        loadupFinalData(dataSrcID, tempsql, CustVarsArray, CustVarTypesArray, CustVarDefaultsArray);
                    }
                }
                catch (Exception t)
                {
                    //Console.WriteLine("An error occurred: '{0}'", t);
                    if (showSLError == "true")
                    {
                        MessageBox.Show("Error occurred in DM List Completed: " + t.Message);
                        mainErrorText = t.Message;
                    }
                }
            }


      private void loadupData()
            {
                MainDataClient client = WCFHelper.CreateService<MainDataClient>("../MainData.svc");
                try
                {
                    client.DataMemberListCompleted += new EventHandler<DataMemberListCompletedEventArgs>(client_DMembersListCompleted);
                    client.DataMemberListAsync(DMid, WhichOne);
                    client.CloseAsync();
                }
                catch (Exception r)
                {
                    if (showSLError == "true")
                    {
                        MessageBox.Show("Error occured loading the data: " + r.Message);
                        mainErrorText = r.Message;
                    }
                }
                finally
                {
                    if (client.State != System.ServiceModel.CommunicationState.Closed)
                    {
                        client.Abort();
                    }
                }
            }

    private void loadupFinalData(int dSID, string mainSql, string[] CustVarArray, string[] CustVarTypesArray, string[] CustVarDefaultsArray)
            {
                try
                {
                    var client2 = WCFHelper.CreateService<MainDataClient>("../MainData.svc");
        
                    client2.FinalValuesListCompleted += (s, e) =>
                    {
                        if (e.Error != null)
                        {
                            if (showSLError == "true")
                            {
                                MessageBox.Show(e.Error.Message);
                            }
                        }
                        //make sure there are results before checking
                        if (e.Result.Count != 0)
                        {
                           
                            try
                            {
                                //Load grid with result set
                                dynamicGrid.ItemsSource = new DataTable(e.Result);
                            }
                            catch (Exception er)
                            {
                            }
                        }
                    };
                    ObservableCollection<string> CVA = new ObservableCollection<string>(CustVarsArray);
                    ObservableCollection<string> CVTA = new ObservableCollection<string>(CustVarTypesArray);
                    ObservableCollection<string> CVDA = new ObservableCollection<string>(CustVarDefaultsArray);
                    client2.FinalValuesListAsync(dSID, mainSql, CVA, CVTA, CVDA);
                }
                catch (Exception r)
                {
                    if (showSLError == "true")
                    {
                        mainErrorText = r.Message;
                    }
                }
            }

    Trace Viewer Log with the first error instance:


    <E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
    <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
    <EventID>131075</EventID>
    <Type>3</Type>
    <SubType Name="Error">0</SubType>
    <Level>2</Level>
    <TimeCreated SystemTime="2013-05-23T19:53:36.2316833Z" />
    <Source Name="System.ServiceModel" />
    <Correlation ActivityID="{feadef04-13a5-4a65-bbba-c7f4d246b7f8}" />
    <Execution ProcessName="WebDev.WebServer40" ProcessID="19648" ThreadID="41" />
    <Channel />
    <Computer>MY-PC</Computer>
    </System>
    <ApplicationData>
    <TraceData>
    <DataItem>
    <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error">
    <TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier>
    <Description>Throwing an exception.</Description>
    <AppDomain>cbc23c64-1-130138120031702260</AppDomain>
    <Exception>
    <ExceptionType>System.ServiceModel.CommunicationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
    <Message>Unrecognized message version.</Message>
    <StackTrace>
    at System.ServiceModel.Channels.ReceivedMessage.ReadStartEnvelope(XmlDictionaryReader reader)
    at System.ServiceModel.Channels.BufferedMessage..ctor(IBufferedMessageData messageData, RecycledMessageState recycledMessageState, Boolean[] understoodHeaders, Boolean understoodHeadersModified)
    at System.ServiceModel.Channels.BinaryMessageEncoderFactory.BinaryMessageEncoder.ReadMessage(ArraySegment`1 buffer, BufferManager bufferManager, String contentType)
    at System.ServiceModel.Channels.HttpInput.DecodeBufferedMessage(ArraySegment`1 buffer, Stream inputStream)
    at System.ServiceModel.Channels.HttpInput.ParseMessageAsyncResult.ContinueReading(Int32 bytesRead)
    at System.ServiceModel.Channels.HttpInput.ParseMessageAsyncResult.OnRead(IAsyncResult result)
    at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
    at System.IO.Stream.ReadWriteTask.InvokeAsyncCallback(Object completedTask)
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.IO.Stream.ReadWriteTask.System.Threading.Tasks.ITaskCompletionAction.Invoke(Task completingTask)
    at System.Threading.Tasks.Task.FinishContinuations()
    at System.Threading.Tasks.Task.FinishStageThree()
    at System.Threading.Tasks.Task.FinishStageTwo()
    at System.Threading.Tasks.Task.Finish(Boolean bUserDelegateExecuted)
    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task&amp; currentTaskSlot)
    at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
    at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
    at System.Threading.ThreadPoolWorkQueue.Dispatch()
    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
    </StackTrace>
    <ExceptionString>System.ServiceModel.CommunicationException: Unrecognized message version.</ExceptionString>
    </Exception>
    </TraceRecord>
    </DataItem>
    </TraceData>
    </ApplicationData>
    </E2ETraceEvent>

    Main Web config

    <authentication mode="Windows">   
     <authorization>
          <allow users="*"/>
        </authorization>
    <httpRuntime maxRequestLength="1048576" executionTimeout="3600" requestValidationMode="2.0" enableVersionHeader="false" requestPathInvalidCharacters=""/>
        <sessionState mode="InProc" stateConnectionString="tcpip=xxx.0.0.1:xxxxx" compressionEnabled="true" sqlConnectionString="data source=xxx.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="60"/>
    <system.net>
        <connectionManagement>
          <add maxconnection = "200" address ="*" />
        </connectionManagement>
      </system.net>
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true">
          <remove name="RadUploadModule"/>
          <add name="RadUploadModule" type="Telerik.Web.UI.RadUploadHttpModule" preCondition="integratedMode"/>
          <add name="httpHeadersCleanup" type="CDR_New.httpHeaderCleanup"/>
        </modules>
        <security>
          <requestFiltering>
            <requestLimits maxAllowedContentLength="1073741824"/>
          </requestFiltering>
        </security>
      </system.webServer>
      <!--<system.diagnostics>
        <sharedListeners>
          <add name="WcfListener"
                  type="System.Diagnostics.XmlWriterTraceListener"
                    initializeData="C:\logs\wcfLog.svclog"/>
        </sharedListeners>
        <sources>
          --><!-- switchValue attribute has no impact on MessageLogging --><!--
          <source name="System.ServiceModel.MessageLogging">
            <listeners>
              <add name="WcfListener" />
            </listeners>
          </source>
          <source name="System.ServiceModel"
                        switchValue="Warning, ActivityTracing"
                        propagateActivity="true" >
            <listeners>
              <add name="WcfListener" />
            </listeners>
          </source>
        </sources>
      </system.diagnostics>-->
      <system.serviceModel>
        <!--<diagnostics>
          <messageLogging
               logEntireMessage="true"
               logMalformedMessages="false"
               logMessagesAtServiceLevel="true"
               logMessagesAtTransportLevel="false"
               maxMessagesToLog="3000"
               maxSizeOfMessageToLog="2000"/>
        </diagnostics>-->
        <behaviors>
          <serviceBehaviors>
            <behavior name="CDR_New.MainDataBehavior">
              <!--Add httpsGetEnabled="true" in the serviceMetadata tag here to all HTTPS access-->
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
              <!--<serviceThrottling maxConcurrentCalls="64" maxConcurrentSessions="400"/>-->
              
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <bindings>
          <customBinding>
            <binding name="customBinding0" receiveTimeout="01:00:00" sendTimeout="01:00:00" openTimeout="01:00:00" closeTimeout="01:00:00">
              <binaryMessageEncoding/>
              <!--<httpsTransport authenticationScheme="Anonymous" />-->
              <httpTransport authenticationScheme="Anonymous"/> <!--Anonymous when running locally, and we change to Negotiate when running the server -->
             
            </binding>
          </customBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        <services>
          <service behaviorConfiguration="CDR_New.MainDataBehavior" name="CDR_New.MainData">
            <endpoint address="" binding="customBinding" bindingConfiguration="customBinding0" contract="CDR_New.MainData"/>
            <endpoint address="mex" binding="customBinding" bindingConfiguration="customBinding0" contract="IMetadataExchange"/>
          </service>
        </services>
      </system.serviceModel>
    </configuration>

    Silverlight project(s) ServiceRef.config

    <configuration>
        <system.serviceModel>
            <bindings>
                <customBinding>
                  <binding name="CustomBinding_MainData" receiveTimeout="01:00:00" sendTimeout="01:00:00" openTimeout="01:00:00" closeTimeout="01:00:00">
                        <binaryMessageEncoding />
                        <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>    
                   
                    </binding>
                </customBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost:52210/MainData.svc" binding="customBinding"
                    bindingConfiguration="CustomBinding_MainData" contract="ServiceReference1.MainData"
                    name="CustomBinding_MainData" />
            </client>
        </system.serviceModel>
    </configuration>


    EDIT: Some of the error stuff I've received here as well:

    Microsoft JScript runtime error: Unhandled Error in Silverlight Application An exception occurred during the operation, making the result invalid.  Check InnerException for exception details.   at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
       at slGridAppFull.ServiceReference1.FinalValuesListCompletedEventArgs.get_Result()
       at slGridAppFull.MainPage.<loadupFinalData>b__182(Object s, FinalValuesListCompletedEventArgs e)
       at slGridAppFull.ServiceReference1.MainDataClient.OnFinalValuesListCompleted(Object state)
    http request to service has exceeded the allotted timeout.  the time allotted to this operation may have been a portion of a longer timout
    SCRIPT5022: Unhandled Error in Silverlight Application Unable to cast object of type 'System.ServiceModel.CommunicationException' to type 'System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]'.   at slGridAppFull.MainPage.client_DMembersListCompleted(Object sender, DataMemberListCompletedEventArgs e)
       at slGridAppFull.ServiceReference1.MainDataClient.OnDataMemberListCompleted(Object state) 

    • Edited by Viplort Friday, May 24, 2013 2:19 PM
    Friday, May 24, 2013 1:33 PM

All replies

  • As an update....it seems (for unknown reasons) that today with my testing (running locally on my pc) that I'm receiving now errors due to what appears to be the browser itself locking up (or something like that).  The grid controls seem to be unresponsive (sorting, etc) and then starts throwing my catch errors first with the "HTTP request to "'my service uri' was aborted.  This may be due to the local channel being closed while the request was still in progress..." 

    Looking at the Task Manager - Processes tab I see that both instances of my dashes (two instances of explorer) are grouped together under one iexplore.exe *32 and the CPU column is at 25+ (seems way high) and fiddler shows an error (no result number) and no response body...just kinda dies.



    • Edited by Viplort Friday, May 24, 2013 5:05 PM
    Friday, May 24, 2013 4:48 PM
  • Hi, what is the issue now?

    From the log you posted(Unrecognized message version.), it seems not the issue you mentioned. Refer an article here to debug your wcf service calls.

    http://msdn.microsoft.com/en-us/vs2010trainingcourse_webservices_topic5#_Toc276335825

    Monday, May 27, 2013 9:02 AM
  • I added that in, but doesn't do much as far as error handling goes now since fiddler isn't throwing an error.  Since I added in the additional time parameters to my web and service config files it seems to simply prolong the inevitable of this error or crash. 

    What I'm seeing is basically is before everything dies Fiddler body size for the service calls starts showing -1 and hanging for a longer period of time before they show their true size, which tells me things are about to get bad.  In my task manager window I see the CPU number climb high for the iexplorer window and then the body size in Fiddler for the service calls start to stay at -1 and then the IE browser window pretty much freezes up and then things die and no error in Fiddler as the result shows -  and the following:

    System.NullReferenceException: Object reference not set to an instance of an object.
       at BinaryMessageFiddlerExtension.BinaryInspector.LoadMessageIntoDocument(Byte[] encodedMessage)
       at BinaryMessageFiddlerExtension.BinaryInspector.UpdateView(Byte[] bytes)

    Also, it has shown the "Protocol Violation Report" popup window "Content-Length mismatch: Request Header indicated 161 bytes, but client sent 0 bytes". 

    Then some of my Try/Catch blocks are hit, which I'm guessing is just because the IE window is now dead and nothing is working.  I did notice in one instance that tow of my values I was expecting to come back on the first call to the service were missing (tempsql and DSID bolded below), which doesn't make sense considering the db isn't being changed and the data is static in there, but even then with these two missing values the error shouldn't have occurred yet it did?

    void client_DMembersListCompleted(object sender, DataMemberListCompletedEventArgs e) { if (e.Error != null) { if (e.Error is FaultException<ExceptionDetail>) { ExceptionDetail exceptDetail = ((FaultException<ExceptionDetail>)e.Error).Detail; HtmlPage.Window.Alert("Error: " + exceptDetail.Message + "\n" + exceptDetail.StackTrace.ToString()); } } try { if (Convert.ToInt32(e.Result.Count) != 0) { string tmpsql = (e.Result[0].ObjSQL.ToString()); int DSID = ((int)e.Result[0].DID); YSs = (e.Result[0].YStyle.ToString()); YTs = (e.Result[0].YThr.ToString()); RSs = (e.Result[0].RStyle.ToString()); RTs = (e.Result[0].RThr.ToString()); CHNs = (e.Result[0].TCN.ToString()); mStyles = (e.Result[0].Style.ToString()); } } catch (Exception t) { //Console.WriteLine("An error occurred: '{0}'", t); if (showSLError == "true") { MessageBox.Show("Error occurred in DM List Completed: " + t.Message); mainErrorText = t.Message; } }

                        loadupFinalData(dataSrcID, tempsql, CustVarsArray, CustVarTypesArray, CustVarDefaultsArray); }


    The data I'm working with doesn't change and isn't large and the error seems elusive as to what it could be and how it fluctuates between crashing anywhere from 15min to an hour. 

    Wednesday, May 29, 2013 4:25 PM