Пример #1
0
        public string TodayAdd(int daysToAdd)
        {
            string result = string.Empty;

            // run the call against the application proxy
            DayNamerServiceApplicationProxy.Invoke(_serviceContext,
                                                   proxy => result = proxy.TodayAdd(daysToAdd));

            return(result);
        }
        internal static void Invoke(SPServiceContext serviceContext, CodeToRunOnApplicationProxy codeBlock)
        {
            if (serviceContext == null)
            {
                throw new ArgumentNullException("serviceContext");
            }

            // get service app proxy from the context
            DayNamerServiceApplicationProxy proxy = (DayNamerServiceApplicationProxy)serviceContext.GetDefaultProxy(typeof(DayNamerServiceApplicationProxy));

            if (proxy == null)
            {
                throw new InvalidOperationException("Unable to obtain object reference to the day namer service application proxy.");
            }

            // run the code block on the proxy
            using (new SPServiceContextScope(serviceContext))
            {
                codeBlock(proxy);
            }
        }