Presentation project
create a WCF service application by right clicking on solution.
we will get Service1.svc and IService1.svc. rename the service if required.
change the web config.
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
<services>
<service name="ContactMangWCF.ContactManagerService" behaviorConfiguration="myBehaviour">
<endpoint address="" binding="webHttpBinding" contract="ContactMangWCF.IContactManagerService"></endpoint>
</service>
</services>
<serviceBehaviors>
<behavior name="myBehaviour">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
---------------------------------------------------------------------------------------
[ServiceContract]
public interface IContactManagerService
{
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "Users")]
[OperationContract]
List<DTO.LoginUser> GetUsers();
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "UserById/{userId}")]
[OperationContract]
DTO.LoginUser GetUserById(string userId);
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "User/{userName}")]
[OperationContract]
DTO.LoginUser GetUserByName(string userName);
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "Contacts/{userId}")]
[OperationContract]
DTO.UserContacts GetContacts(string userId);
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "Register")]
[OperationContract]
DTO.LoginUser RegisterLoginUser(DTO.LoginUser lu);
}
----------------------------------------------------------------------------------------
public class ContactManagerService : IContactManagerService
{
#region Contacts
public DTO.UserContacts GetContacts(string userId)
{
ContactService contactService = new ContactService();
return contactService.GetContacts(Convert.ToInt64(userId));
}
#endregion
#region User
public List<DTO.LoginUser> GetUsers()
{
UserService us = new UserService();
return us.GetAllLoginUsers();
}
public DTO.LoginUser GetUserById(string userId)
{
UserService us = new UserService();
return us.GetLoginUser(Convert.ToInt64(userId));
}
public DTO.LoginUser GetUserByName(string userName)
{
UserService us = new UserService();
return us.GetLoginUser(userName);
}
#endregion
#region Register
public DTO.LoginUser RegisterLoginUser(DTO.LoginUser lu)
{
UserService us = new UserService();
var a = us.RegisterLoginUser(lu);
return a;
}
#endregion
}
------------------------------------------------
set this project as start up project. run
http://localhost:35848/ContactManagerService.svc/users
output : [{"Id":1,"Name":"AAA","Password":"aaa","Status":"A"},{"Id":2,"Name":"BBB","Password":"bbb","Status":"A"},{"Id":3,"Name":"CCC","Password":"ccc","Status":"A"},{"Id":4,"Name":"DDD","Password":"ddd","Status":"A"},{"Id":5,"Name":"FFF","Password":"fff","Status":"A"},{"Id":6,"Name":"KKK","Password":"kkk","Status":"A"}]
http://localhost:35848/ContactManagerService.svc/UserById/6
output : {"Id":6,"Name":"KKK","Password":"kkk","Status":"A"}
post methods need to be checked using Postman or through application...
----------------------------------------- End -----------------------------------------------------
create a WCF service application by right clicking on solution.
we will get Service1.svc and IService1.svc. rename the service if required.
change the web config.
<endpointBehaviors>
<behavior>
<webHttp />
</behavior>
</endpointBehaviors>
<services>
<service name="ContactMangWCF.ContactManagerService" behaviorConfiguration="myBehaviour">
<endpoint address="" binding="webHttpBinding" contract="ContactMangWCF.IContactManagerService"></endpoint>
</service>
</services>
<serviceBehaviors>
<behavior name="myBehaviour">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
---------------------------------------------------------------------------------------
[ServiceContract]
public interface IContactManagerService
{
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "Users")]
[OperationContract]
List<DTO.LoginUser> GetUsers();
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "UserById/{userId}")]
[OperationContract]
DTO.LoginUser GetUserById(string userId);
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "User/{userName}")]
[OperationContract]
DTO.LoginUser GetUserByName(string userName);
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "Contacts/{userId}")]
[OperationContract]
DTO.UserContacts GetContacts(string userId);
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "Register")]
[OperationContract]
DTO.LoginUser RegisterLoginUser(DTO.LoginUser lu);
}
----------------------------------------------------------------------------------------
public class ContactManagerService : IContactManagerService
{
#region Contacts
public DTO.UserContacts GetContacts(string userId)
{
ContactService contactService = new ContactService();
return contactService.GetContacts(Convert.ToInt64(userId));
}
#endregion
#region User
public List<DTO.LoginUser> GetUsers()
{
UserService us = new UserService();
return us.GetAllLoginUsers();
}
public DTO.LoginUser GetUserById(string userId)
{
UserService us = new UserService();
return us.GetLoginUser(Convert.ToInt64(userId));
}
public DTO.LoginUser GetUserByName(string userName)
{
UserService us = new UserService();
return us.GetLoginUser(userName);
}
#endregion
#region Register
public DTO.LoginUser RegisterLoginUser(DTO.LoginUser lu)
{
UserService us = new UserService();
var a = us.RegisterLoginUser(lu);
return a;
}
#endregion
}
------------------------------------------------
set this project as start up project. run
http://localhost:35848/ContactManagerService.svc/users
output : [{"Id":1,"Name":"AAA","Password":"aaa","Status":"A"},{"Id":2,"Name":"BBB","Password":"bbb","Status":"A"},{"Id":3,"Name":"CCC","Password":"ccc","Status":"A"},{"Id":4,"Name":"DDD","Password":"ddd","Status":"A"},{"Id":5,"Name":"FFF","Password":"fff","Status":"A"},{"Id":6,"Name":"KKK","Password":"kkk","Status":"A"}]
http://localhost:35848/ContactManagerService.svc/UserById/6
output : {"Id":6,"Name":"KKK","Password":"kkk","Status":"A"}
post methods need to be checked using Postman or through application...
----------------------------------------- End -----------------------------------------------------
Comments
Post a Comment