|
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using System.Security.Permissions;
using log4net;
using System.IO;
using System.Runtime.Serialization;
namespace WtfService
{
// Start the service and browse to http://<machine_name>:<port>/Service1/help to view the service's generated help page
// NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
// a single instance of the service to process all calls.
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
// NOTE: If the service is renamed, remember to update the global.asax.cs file
public class WtfSvc
{
private static readonly ILog log = LogManager.GetLogger(typeof(WtfSvc));
/// <summary>
/// Demonstrates http get where parameters are passed in the URL.
/// Also requires the user to be in the role of 'WtfUser'.
/// </summary>
/// <param name="firstName"></param>
/// <param name="lastName"></param>
/// <returns></returns>
[WebGet(UriTemplate = "HelloWorld/{firstName}/{lastName}")]
[PrincipalPermission(SecurityAction.Demand, Role = "WtfUser")]
public string HelloWorld(string firstName, string lastName)
{
return string.Format("Hello {0} {1}", firstName, lastName);
}
/// <summary>
/// Demonstrates http post where request body contains two parameters of simple type.
/// Also requires the user to be in the role of 'WtfUser'
/// </summary>
/// <param name="firstName">comes from the json content of the body of the post e.g. "{\"firstName\" : \"John\", \"lastName\" : \"Doe\" } }"</param>
/// <param name="lastName">comes from the json content of the body of the post e.g. "{\"firstName\" : \"John\", \"lastName\" : \"Doe\" } }"</param>
/// <returns></returns>
[WebInvoke(Method = "POST", UriTemplate = "HelloWorldPostSimple")]
[PrincipalPermission(SecurityAction.Demand, Role = "WtfUser")]
public string HelloWorldPostSimple(string firstName, string lastName)
{
return string.Format("Hello {0} {1}", firstName, lastName);
}
/// <summary>
/// Demonstrates http post where request body contains the json string representing an object of type Person.
/// Also requires the user to be in the role of 'WtfUser'
/// </summary>
/// <param name="person">comes from the json content of the body of the post e.g. "{\"person\":{\"FirstName\" : \"John\", \"LastName\" : \"Doe\" } }"</param>
/// <returns></returns>
[WebInvoke(Method = "POST", UriTemplate = "HelloWorldPostComplex")]
[PrincipalPermission(SecurityAction.Demand, Role = "WtfUser")]
public string HelloWorldPostComplex(Person person)
{
return string.Format("Hello {0} {1}", person.FirstName, person.LastName);
}
}
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Has a background in Finance and Software development.
Has worked as a RAD developer for the likes of Credit-Suisse and Westpac Banking corporation.
Currently self-employed working on some personal projects.