Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I just developed a wcf application . Below is the code:

1)IService1.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using DAL;
namespace Demo
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{

[OperationContract]
string GetData(int value);

[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);

// TODO: Add your service operations here

//Operation Contracts starts here
[OperationContract]

string Test();

[OperationContract]
List<client> GetAllClients();
[OperationContract]
Client GetClientByID(long ClientID);

[OperationContract]
Boolean UpdateClient(Client clientObj);
[OperationContract]
List<client> SearchClients(Client clientObj);
[OperationContract]
List<product> GetAllProducts();
[OperationContract]
Product GetProductByID(long ProductID);
[OperationContract]
Boolean UpdateProduct(Product productObj);
[OperationContract]
List<product> SearchProducts(Product productObj);

[OperationContract]
List<billing> GetAllBills();
[OperationContract]
Invoice GetInvoiceByID(long InvoiceID);
[OperationContract]
Boolean UpdateInvoice(Invoice invoiceObj);
[OperationContract]
List<invoice> SearchInvoices(Invoice invoiceObj);

}


// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";

[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}

[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}



}
}


2) Service1.svc.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using DAL;

namespace Demo
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}

public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}

public string Test()
{
return "hello";
}
public List<client> GetAllClients()
{
return DAL.Class1.GetAllClients();
}



public Client GetClientByID(long ClientID)
{
return DAL.Class1.GetClientByID(ClientID);
}

public Boolean UpdateClient(Client clientObj)
{
return DAL.Class1.UpdateClient(clientObj);
}
public List<client> SearchClients(Client clientObj)
{
return DAL.Class1.SearchClients(clientObj);
}
public List<product> GetAllProducts()
{
return DAL.Class1.GetAllProducts();
}
public Product GetProductByID(long ProductID)
{
return DAL.Class1.GetProductByID(ProductID);
}
public Boolean UpdateProduct(Product productObj)
{
return DAL.Class1.UpdateProduct(productObj);
}
public List<product> SearchProducts(Product productObj)
{
return DAL.Class1.SearchProducts(productObj);
}

public List<billing> GetAllBills()
{
return DAL.Class1.GetAllBills();
}
public Invoice GetInvoiceByID(long InvoiceID)
{
return DAL.Class1.GetInvoiceByID(InvoiceID);
}
public Boolean UpdateInvoice(Invoice invoiceObj)
{
return DAL.Class1.UpdateInvoice(invoiceObj);
}
public List<invoice> SearchInvoices(Invoice invoiceObj)
{
return DAL.Class1.SearchInvoices(invoiceObj);
}



}
}

How to develop web apis for this wcf code. Is it possible to implement web api concept using asp.net in this wcf application.
Posted

1 solution

No. ASP.NET WepApi is a new technology for building webservices on the top of Http. WebApi itself is a combined feature of WCF and ASP.NET MVC.

Hope this helps
 
Share this answer
 
Comments
Sunil Pavithran Nair 21-Aug-13 1:23am    
how can i develop web api based on this following code above??
Jameel VM 21-Aug-13 1:31am    
this link will help u http://www.asp.net/web-api

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900