Hey all, I am running class on our IIS 7 server with all the Sharepoint yimmer yammer installed. I have webservice that I created using the walkthrough on the MSDN site.
I found that I needed to use the ElevatedPrivilleges call in order to get my LINQ classes to work.
Once I did that, it seems to cause my NLog based logger to NOT be able to find the web.nlog file that I put in the same directory as the web.config file as the NLog documenation said to.
Any log statements outside the the delegate here work just fine, anything inside never comes out in the log file.
What gives, what’s really happening in that delegate?
using System;
using System.Web.Services;
using Notification.DAL;
using SharePointConnector;
using NLog;
using Microsoft.SharePoint;
namespace NotificationReceiverService
{
[WebService(Namespace = "http://midwestiso.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
private static Logger logger = LogManager.GetCurrentClassLogger();
private static readonly String MACHINE_NAME = Environment.MachineName.ToUpper();
public Service()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello World, You've contacted the Notifications Receiver Service. " +
"Please refer to the WSDL for the other available methods";
}
[WebMethod]
public string EchoMessage(string MESSAGE_TEMPLATE_NAME, string MESSAGE_SUBJECT, string MESSAGE_TEXT_SUMMARY,
string MESSAGE_TEXT_DETAIL, string MESSAGE_TEXT_CON_OPS)
{
return String.Format("You called EchoMessage and told me {0}, {1}, {2}, {3}, {4}",
MESSAGE_TEMPLATE_NAME, MESSAGE_SUBJECT, MESSAGE_TEXT_SUMMARY, MESSAGE_TEXT_DETAIL, MESSAGE_TEXT_CON_OPS);
}
[WebMethod]
public string SendMessage(string MESSAGE_TEMPLATE_NAME, string MESSAGE_SUBJECT, string MESSAGE_TEXT_SUMMARY,
string MESSAGE_TEXT_DETAIL, string MESSAGE_TEXT_CON_OPS)
{
logger.Info("------" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " starting on " + MACHINE_NAME + "------");
try
{
//SPSecurity.RunWithElevatedPrivileges(delegate
// {
int? newNotificationId = 0;
using (var db = new MISO_IR_IntegrationDataContext())
{
logger.Error("Message Received is: {0} - {1} - {2} - {3} - {4} - {5}",
DateTime.UtcNow.AddHours(-5), MESSAGE_TEMPLATE_NAME.Trim(),
MESSAGE_SUBJECT.Trim(), MESSAGE_TEXT_SUMMARY.Trim(),
MESSAGE_TEXT_DETAIL.Trim(), MESSAGE_TEXT_CON_OPS.Trim());
int dbProcReturnCode = db.InsertReceivedNotification(DateTime.UtcNow.AddHours(-5),
MESSAGE_TEMPLATE_NAME.Trim(), MESSAGE_SUBJECT.Trim(), MESSAGE_TEXT_SUMMARY.Trim(),
MESSAGE_TEXT_DETAIL.Trim(), MESSAGE_TEXT_CON_OPS.Trim(), ref newNotificationId);
if (dbProcReturnCode == 0)
{
logger.Info("Notification saved to DB with ID: {0}", newNotificationId);
logger.Debug("Getting read to call CreatePublishingPagefromNotification");
// PagePublisher.CreatePublishingPagefromNotification((int)newNotificationId);
logger.Debug("Complete calling CreatePublishingPagefromNotification without exception");
}
else
{
throw new Exception("Unable to find mapping for this MESSAGE_TEMPLATE, saved the message to the notification table with ERRORNOMAPPING code, aborting further processing");
}
}
// });
}
catch (Exception ex)
{
logger.ErrorException(ex.Message, ex);
return "ERRORPOOP";
}
finally
{
logger.Info("------" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " COMPLETED ------");
}
return "OK";
}
}
}
That elevated priveleges delegate runs the code inside it as the web application account (i.e. the code no longer impersonates the user running the code).
Find out what account the web application is running under and then figure out why the logging messages change with the user.