using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Web.Services; using System.Xml; using System.Xml.Serialization; using BeWo.Data; using BeWo.Data.Access; using BeWo.Service.ServiceContracts; using BeWo.Service.ServiceImplementations; using BeWoPlanerMobil.Service; using BS.Shared; using BS.Shared.Core; using Newtonsoft.Json; using ASPHibernateSessionManager = BeWoPlanerMobil.Service.ASPHibernateSessionManager; using Formatting = Newtonsoft.Json.Formatting; namespace BeWoPlanerMobil { [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] // Wenn der Aufruf dieses Webdiensts aus einem Skript mithilfe von ASP.NET AJAX zulässig sein soll, heben Sie die Kommentarmarkierung für die folgende Zeile auf. [System.Web.Script.Services.ScriptService] public class TestWebService : WebService { protected readonly ICustomerService CustomerService = new MobileSessionFacade().CustomerService; protected readonly IUserService UserService = new MobileSessionFacade().UserService; protected readonly IEmployeeService EmployeeService = new MobileSessionFacade().EmployeeService; [WebMethod(EnableSession = true)] public bool TestLogin(string pUserName, string pPassword, string pTenant) { var result = false; MobileSessionFacade.Tenant = pTenant; SessionFacade.Tenant = pTenant; ASPHibernateSessionManager.ConfigureHibernateSessionForWebService(); var s = new UserServiceImp(); if (s.IsUserValid(pUserName, pPassword, null, "MobilClient", false, "") == UserValidationResult.UserValid) { var user = DAOFactory.UserDAO.FindUserByLoginName(pUserName); if(user == null || !DAOFactory.UserDAO.CheckPassword(user, pPassword)) { result = false; } else { MobileSessionFacade.LoggedInUser = user; result = true; } } return result; } [WebMethod(EnableSession = true)] public string TestFunktion(long pCustomerOid) { MobileSessionFacade.Tenant = "demo"; ASPHibernateSessionManager.ConfigureHibernateSessionForWebService(); var result = CustomerService.GetCompactCustomerDC(pCustomerOid); return SerializeObject(result); } [WebMethod(EnableSession = true)] public string TestMitFehler() { throw new NotImplementedException("Das ist nur eine Testausnahme!"); } private static string SerializeObject(object obj) { return JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new ShouldSerializeContractResolver(), ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); } [WebMethod] public string JsonTest() { var result = new List(); var obj1 = new ListObject("Child 1", 0, true, new List()); var obj2 = new ListObject("Child 2", 6, true, new List()); var obj3 = new ListObject("Child 3", 33, true, new List()); var obj4 = new ListObject("Parent", 37, true, new List{obj1, obj2, obj3}); result.Add(obj4); return JsonConvert.SerializeObject(result); } } public class ListObject { public string Name { get; set; } public int Count { get; set; } public bool IsEnabled { get; set; } public List Children { get; set; } public ListObject(string name, int count, bool isEnabled, List children) { Name = name; Count = count; IsEnabled = isEnabled; Children = children; } } }