1

I have developed a web service using C# dot net coding which will connect to SharePoint online - and that web service I have hosted in one of the SharePoint on-premise IIS front end server - but I see some strange behavior. If we call that web service first time in a day using nintex workflow we get the below error:

**The GetListAttachmentsAndCopyToSPOnline workflow has ended unexpectedly for (no title).    
For more information, please read this article: http://go.microsoft.com/fwlink/?LinkID=323543&clcid=0x409    
Click here to view the workflow status.**

But once we restart the particular web service((IIS site)from IIS - everything start working perfectly. I mean in order to work with that web service every day at least once we need to restart the web service(IIS site) from the IIS....Not getting any clue why is this behavior? Any help would be much appreciated.

Sample web service code:

using (ClientContext ctx = new ClientContext(siteURL))
                {
                    bool isSONumberFound = false;
                    string userName = "MyUserName";
                    string passWord = "MyPassword";

                    if (salesOrderNumber.Length <= 7)
                    {
                        salesOrderNumber = "000" + salesOrderNumber;
                    }

                    using (SecureString securedPassWord = new SecureString())
                    {
                        foreach (char c in passWord.ToCharArray()) securedPassWord.AppendChar(c);
                        ctx.Credentials = new SharePointOnlineCredentials(userName, securedPassWord);
                        Web web = ctx.Web;
                        try
                        {
                            ctx.Load(web);
                            ctx.ExecuteQuery();
                            List list = web.Lists.GetByTitle(documentLibrayName);
                            var camelQuery = new CamlQuery() { ViewXml = "<View><Query><Where><Eq><FieldRef Name='OrderID' /><Value Type='Text'>" + salesOrderNumber + "</Value></Where></Query></View>" };
                            var queryResults = list.GetItems(camelQuery);
                            ctx.Load(queryResults);
                            ctx.ExecuteQuery();
                            int countSalesOrder = queryResults.Count;

                            if (countSalesOrder >= 1)
                            {
                                isSONumberFound = true;

                                using (StreamWriter w = System.IO.File.AppendText(logFileName))
                                {
                                    string logMessageSONotFound = "Sales Order Number: " + salesOrderNumber + "is found in the target document library: " + documentLibrayName + "of" + siteURL + ", so please enter the valid SO number";
                                    Log(logMessageSONotFound, w);
                                    w.Flush();
                                    w.Close();
                                    w.Close();
                                }

                            }
                            else
                            {
                                isSONumberFound = false;

                                using (StreamWriter w = System.IO.File.AppendText(logFileName))
                                {
                                    string logMessageSONotFound = "Sales Order Number: " + salesOrderNumber + "is not found in the target document library: " + documentLibrayName + "of"+ siteURL+", so please enter the valid SO number";
                                    Log(logMessageSONotFound, w);
                                    w.Flush();
                                    w.Close();
                                    w.Close();
                                }

                            }

                        }
                        catch (Exception ex)
                       {
                            using (StreamWriter w = System.IO.File.AppendText(logFileName))
                            {
                                Log(ex.Message.ToString(), w);
                            }

                        }

                    }    
                    return isSONumberFound;

                }

            }

        }

    }

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.