About us |  Help us improve
intelliVERB - Get a fair search of the Internet !
Visual studio .net
SQL Server
Oracle
Main  >  Web Service  >  Server service Email this page to friend
Server service
 
 
 
 
 
C#Server serviceTop

 /// <summary>
 /// MyWebService is the server side class
 /// It is actually the webservice class
 /// </summary>

 public class MyWebService : System.Web.Services.WebService
 {
  public MyWebService()
  {
   //CODEGEN: This call is required by the ASP.NET Web Services Designer
   InitializeComponent();
  }
  /// <summary>
  /// Employee class definition
  /// The class must be Serializable
  /// to be expose through the web service
  /// </summary>

  [Serializable()]
  public class Employee
  {
   //Personal Information
   public string SSN;
   public string FirstName;
   public string LastName;
   //Payroll information
   public double Salary;
   public int Vacation;
   //Benefit information
   public bool HasMedical;
   public bool HasDental;
   public bool HasVision;
   /// <summary>
   /// In order to be Serializable
   /// employee class must have a
   /// default constructor
   /// </summary>

   public Employee()
   {}
   
  }
  
  /// <summary>
  /// Authentication class derived from the
  /// SoapHeader class
  /// </summary>

  public class Authentication : SoapHeader
  {
   //Authentication parameters
   public int Client_Id;
   public string Client_Code;
   public string Client_Token;

  }

  //Authentication variable to receive the content of the header
  public Authentication Authorization;
  
  [WebMethod]
  //Set both the the Web service and the client as recipient of the SoapHeader
  [SoapHeader("Authorization", Direction=SoapHeaderDirection.InOut)]
  public bool Process_NewEmployee(Employee oEmployee)
  {
   try
   {
    //Authenticate the client service
    //with some database routine

    if (isValidClient(Authorization.Client_Id, Authorization.Client_Code, Authorization.Client_Token))
    {
     //Call create employee routine
    }
    else
    {
     //Log attempt to the system
     return false;
    }
   }
   catch (Exception ex)
   {
    //Log error message
    return false;
   }
   return true;
  }
  //Function in charge of validating the client credentials
  private bool isValidClient(int ClientId,string ClientCode,string ClientToken)
  {
   //Call database query to check client credentials
   //For testing purpose lets validate inputs against constant values

   if ((ClientId==123456)&&
    (ClientCode=="abc123")&&
    (ClientToken=="XDEVGFG-jjgfgfg-1264644-hfgfgfg"))
   {
    //Log query call
    return true;
   }
   else
   {
    //Log failure
    return false;
   }

  }
  /*Enabling session state for web method
   When set to true the method will maintain
   state of object across sessions.
   The default value is set to false
   */
  //[WebMethod (EnableSession=true)]

  /*Caching results for web method
   When define ASP.NET caches response for the
   duration specified in seconds.
   The default value is 0
   */
   //[WebMethod (CacheDuration=30)]

  /*Buffering responses for web method
   When set to true ASP.NET keeps all serialized
   responses of the method in a memory buffer
   before sending them to the client. It has the
   advantage of improving performance of the
   worker process and IIS.
   */
  //[WebMethod (BufferResponse=false)]

  /*Specifying a description for web method
   When specify it appears as the DescriptionAttribute
   for the method.
   Its an attribute of string type.
   */

  [WebMethod (Description="Process an employee benefit data")]
  /*Specifying alias for a web method
   When define the method is identify across SOAP
   messages by this value instead of the method name.
   MessageName attribute can be use to uniquely
   identify overloaded web methods.
   */
  //[WebMethod(MessageName="SaveEmployeeBenefit")]
  /*Specifying automatic transaction type for a web method
   TransactionOption attribute can take values:
   Disabled: The method will ignore any transaction
   in the current context.
   NotSupported: The method will run in context
   with no governing transaction
   Required: The method will Shares a transaction,
   if one exists, and creates a new transaction, if necessary.
   RequiresNew:The method will run in the context of
   a new transaction, regardless of the state of the current context.
   Supported: The method will Shares a transaction, if one exists.
   System.EnterpriseService.dll is required in order to enable
   transaction in a web method.
   */
  //[WebMethod (TransactionOption=TransactionOption.Required)]

  public bool Process_EmployeeBenefit(Employee oEmployee)
  {
   try
   {
    //Call employee payroll routine
   }
   catch (Exception ex)
   {
    //Log error message
    return false;
   }
   return true;
  }
  [WebMethod]
  public bool Process_EmployeePayroll(Employee oEmployee)
  {
   try
   {
    //Call employee payroll routine
   }
   catch (Exception ex)
   {
    //Log error message
    return false;
   }
   return true;
  }

  #region Component Designer generated code
  //Required by the Web Services Designer
  //This portion has been removed for clarity needs

  #endregion

 }

You last visited
ASP.net Interview Q.
Web method
Client service
Soap header
Sql Server Basic functions
XML
DDL Sql Server
Web Objects
 
 
Make a secure donation now with PayPal!