Create WCF Project
Open Visual Studio 2017 Community. Create New Project name and save solution in C:\UsedCar\UsedCarService and click Next button
Create a folder Model for UsedCar project
5 Likes
Right click Model and selecte New Item
Select ADO.NET Entity Model and Name UsedCarDBEntity and name UsedCarDBEntity
Select Entity FrameWork from database.
Create connection string.
Open Visual Studio 2017 Community.
Enter your database name and select UsedCar database .
Click Next
Select Entity Framework 5.0. Click Next
Select All tables Click Finish
WCF Sevice
IService1.
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; namespace BrandonWebService { // 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] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GroceryCategory/")] List<BrandonDataContract.GroceryCategoryDataContract> GroceryCategory(); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/SubGroceryCategory/{categoryId}")] List<BrandonDataContract.SubGroceryCategoryDataContract> SubGroceryCategory(string categoryId); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/UserAllGroceryItems/{userAccount}")] List<BrandonDataContract.UserGroceryItemDataContract> UserAllGroceryItems(string userAccount); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/UserItemByCategory/{userAccount}/{category}")] List<BrandonDataContract.UserGroceryItemDataContract> UserItemByCategory(string userAccount, string category); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/UserItemBySubCategory/{userAccount}/{category}/{subCategory}")] List<BrandonDataContract.UserGroceryItemDataContract> UserItemBySubCategory(string userAccount, string category, string subCategory); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/UserGroceryItems/{userAccount}/{status}")] List<BrandonDataContract.UserGroceryItemDataContract> UserGroceryItems(string userAccount, string status); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/UserPromoItems/{userAccount}")] List<BrandonDataContract.UserGroceryItemDataContract> UserPromoItems(string userAccount); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/UserSortItems/{userAccount}/{sortItem}")] List<BrandonDataContract.UserGroceryItemDataContract> UserSortItems(string userAccount, string sortItem); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/MasterGroceryItems/")] List<BrandonDataContract.GroceryMasterItemDataContract> MasterGroceryItems(); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/UOMList/")] List<BrandonDataContract.UOMDataContract> UOMList(); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/CouponList/{userAccount}/{couponType}")] List<BrandonDataContract.CouponDataContract>CouponList(string userAccount, string couponType); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/UserKitchenWareList/{userAccount}")] List<BrandonDataContract.KitchenwareDataContract> UserKitchenWareList(string userAccount); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/UserKitchenWareByCategory/{userAccount}/{category}")] List<BrandonDataContract.KitchenwareDataContract> UserKitchenWareByCategory(string userAccount, string category); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/KitchenWareMasterList/")] List<BrandonDataContract.KitchenwareMasterDataContract>KitchenWareMasterList(); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/KitchenWareCategory/")] List<BrandonDataContract.KitchenWareCategoryDataContract> KitchenWareCategory(); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/UserKitchenByCategory/{userAccount}/{category}")] List<BrandonDataContract.KitchenwareDataContract> UserKitchenByCategory(string userAccount, string category); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/ShoppingCartByOrderID/{orderId}")] List<BrandonDataContract.ShoppingCartDataContract> ShoppingCartByOrderID(string orderId); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/ShoppingCartByAcct/{userAccount}")] List<BrandonDataContract.ShoppingCartDataContract> ShoppingCartByAcct(string userAccount); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/ShoppingCart/{userAccount}/{todayDate}")] List<BrandonDataContract.ShoppingCartDataContract> ShoppingCart(string userAccount, string todayDate); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GroceryOrder/{userAccount}/{todayDate}")] List<BrandonDataContract.OrderDataContract> GroceryOrder(string userAccount, string todayDate); [OperationContract] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GroceryOrderDetail/{OrderId}")] List<BrandonDataContract.OrderDataContract> GroceryOrderDetail(string OrderId); // Use a data contract as illustrated in the sample below to add composite types to service operations. [DataContract] public class BrandonDataContract { [DataContract] public class GroceryCategoryDataContract { [DataMember] public int ID { get; set; } [DataMember] public string groceryCategory1 { get; set; } } [DataContract] public class SubGroceryCategoryDataContract { [DataMember] public int ID { get; set; } [DataMember] public int Category { get; set; } [DataMember] public string SubCategory { get; set; } } [DataContract] public class UserGroceryItemDataContract { [DataMember] public int ID { get; set; } [DataMember] public string userAccount { get; set; } [DataMember] public string category { get; set; } [DataMember] public string subCategory { get; set; } [DataMember] public string itemNameEN { get; set; } [DataMember] public string itemNameVN { get; set; } [DataMember] public string UOM { get; set; } [DataMember] public decimal itemPrice { get; set; } [DataMember] public int promotion { get; set; } [DataMember] public int coupons { get; set; } [DataMember] public string itemImages { get; set; } [DataMember] public int itemStatus { get; set; } } [DataContract] public class GroceryMasterItemDataContract { [DataMember] public int ID { get; set; } [DataMember] public int category { get; set; } [DataMember] public string subCategory { get; set; } [DataMember] public string itemNameEN { get; set; } [DataMember] public string itemNameVN { get; set; } [DataMember] public string UOM { get; set; } [DataMember] public string imageURL { get; set; } [DataMember] public string imagePath { get; set; } } [DataContract] public class UOMDataContract { [DataMember] public int ID { get; set; } [DataMember] public string UOM1 { get; set; } } [DataContract] public class KitchenwareDataContract { [DataMember] public int ID { get; set; } [DataMember] public string userAccount { get; set; } [DataMember] public string productCategory { get; set; } [DataMember] public string productSubCategory { get; set; } [DataMember] public string productNameEN { get; set; } [DataMember] public string productNameVN { get; set; } [DataMember] public string productMade { get; set; } [DataMember] public string productDetail { get; set; } [DataMember] public string productColor { get; set; } [DataMember] public string productSize { get; set; } [DataMember] public Nullable<decimal> productPrice { get; set; } [DataMember] public string productImages { get; set; } } [DataContract] public class CouponDataContract { [DataMember] public int ID { get; set; } [DataMember] public string couponType { get; set; } [DataMember] public string category { get; set; } [DataMember] public string couponCode { get; set; } [DataMember] public string itemImage { get; set; } [DataMember] public string userAccount { get; set; } [DataMember] public string couponNotes { get; set; } [DataMember] public string itemNameVN { get; set; } [DataMember] public string itemNameEN { get; set; } [DataMember] public string UOM { get; set; } [DataMember] public Nullable<decimal> itemPrice { get; set; } [DataMember] public Nullable<decimal> itemCouponPrice { get; set; } [DataMember] public Nullable<decimal> itemSave { get; set; } [DataMember] public Nullable<System.DateTime> couponStartDate { get; set; } [DataMember] public Nullable<System.DateTime> couponEndDate { get; set; } [DataMember] public Nullable<int> userItemID { get; set; } } [DataContract] public class KitchenwareMasterDataContract { [DataMember] public int ID { get; set; } [DataMember] public string productCategory { get; set; } [DataMember] public string productNameEN { get; set; } [DataMember] public string productNameVN { get; set; } [DataMember] public string productMade { get; set; } [DataMember] public string productDetail { get; set; } [DataMember] public string productColor { get; set; } [DataMember] public string productSize { get; set; } [DataMember] public Nullable<decimal> productPrice { get; set; } [DataMember] public string productImages { get; set; } } [DataContract] public class KitchenWareCategoryDataContract { [DataMember] public int ID { get; set; } [DataMember] public string KichenWareCatEN { get; set; } [DataMember] public string KichenWareCatVN { get; set; } [DataMember] public string FolderName { get; set; } } [DataContract] public class KitchenWareColorDataContract { [DataMember] public int ID { get; set; } [DataMember] public string Color { get; set; } } [DataContract] public class ShoppingCartDataContract { [DataMember] public int ID { get; set; } [DataMember] public string orderID { get; set; } [DataMember] public string userAccount { get; set; } [DataMember] public string itemNameVN { get; set; } [DataMember] public string itemNameENG { get; set; } [DataMember] public decimal itemPrice { get; set; } [DataMember] public string uom { get; set; } [DataMember] public int quantity { get; set; } [DataMember] public int discount { get; set; } [DataMember] public decimal total { get; set; } [DataMember] public Nullable<System.DateTime> shoppingDate { get; set; } [DataMember] public int shoppingMonth { get; set; } [DataMember] public int shoppingYear { get; set; } } [DataContract] public class OrderDataContract { [DataMember] public int ID { get; set; } [DataMember] public string userAccount { get; set; } [DataMember] public string orderId { get; set; } [DataMember] public Nullable<System.DateTime> shoppingDate { get; set; } [DataMember] public string orderStatus { get; set; } [DataMember] public string orderType { get; set; } [DataMember] public Nullable<System.DateTime> pickupDate { get; set; } [DataMember] public string pickupTime { get; set; } //[DataMember] public decimal grandTotal { get; set; } } } }
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <appSettings> <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> </appSettings> <system.web> <compilation targetFramework="4.6" debug="true" /> <httpRuntime targetFramework="4.6" /> </system.web> <system.serviceModel> <services> <service name="BrandonWebService.Service1" behaviorConfiguration="serviceBehavior"> <endpoint address="" binding="webHttpBinding" contract="BrandonWebService.IService1" behaviorConfiguration="RESTEndpointBehavior"></endpoint> </service> </services> <behaviors> <endpointBehaviors> <behavior name="RESTEndpointBehavior"> <webHttp /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="serviceBehavior"> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> <behavior name=""> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <protocolMapping> <add binding="webHttpBinding" scheme="http" /> </protocolMapping> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> <standardEndpoints> <webScriptEndpoint> <standardEndpoint name="" crossDomainScriptAccessEnabled="true" /> </webScriptEndpoint> </standardEndpoints> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Headers" value="Content-Type" /> </customHeaders> </httpProtocol> <!-- To browse web app root directory during debugging, set the value below to true. Set to false before deployment to avoid disclosing web app folder information. --> <directoryBrowse enabled="true" /> </system.webServer> <connectionStrings> <add name="GroceryDataUtilities" connectionString="metadata=res://*/Models.GroceryDataUtilities.csdl|res://*/Models.GroceryDataUtilities.ssdl|res://*/Models.GroceryDataUtilities.msl;provider=System.Data.SqlClient;provider connection string="data source=BRANDONPH\SQLEXPRESS;initial catalog=BrandonDBGrocery;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework> </configuration>