Contract Type is Not Attributed with ServiceContractAttribute

Contract Type is Not Attributed with ServiceContractAttribute

 

ServiceHost host = new ServiceHost(typeof(Inventory.InventoryService));
host.AddServiceEndpoint(typeof(Inventory.InventoryService), new NetTcpBinding(),
    "net.tcp://localhost:9000/GetInventory");
host.Open();

If your ServiceContract attribute is on the Interface not the concrete class, try the following:

ServiceHost host = new ServiceHost(typeof(Inventory.InventoryService));
host.AddServiceEndpoint(typeof(Inventory.IInventoryService), new NetTcpBinding(),
    "net.tcp://localhost:9000/GetInventory");
host.Open();

WCF and ASP.NET Web API

Bảng dưới đây mô tả sự khác nhau giữa WCF and ASP.NET Web API, từ bảng này chúng ta có thể lựa chọn công nghệ phù hợp cho từng bài toán.

WCF ASP.NET Web API
Enables building services that support multiple transport protocols (HTTP, TCP, UDP, and custom transports) and allows switching between them. HTTP only. First-class programming model for HTTP. More suitable for access from various browsers, mobile devices etc enabling wide reach.
Enables building services that support multiple encodings (Text, MTOM, and Binary) of the same message type and allows switching between them. Enables building Web APIs that support wide variety of media types including XML, JSON etc.
Supports building services with WS-* standards like Reliable Messaging, Transactions, Message Security. Uses basic protocol and formats such as HTTP, WebSockets, SSL, JQuery, JSON, and XML. There is no support for higher level protocols such as Reliable Messaging or Transactions.
Supports Request-Reply, One Way, and Duplex message exchange patterns. HTTP is request/response but additional patterns can be supported through SignalRand WebSockets integration.
WCF SOAP services can be described in WSDL allowing automated tools to generate client proxies even for services with complex schemas. There is a variety of ways to describe a Web API ranging from auto-generated HTML help page describing snippets to structured metadata for OData integrated APIs.
Ships with the .NET framework. Ships with .NET framework but is open-source and is also available out-of-band as independent download.

Hướng dẫn xây dựng WCF Services

Tạo dự án mới, chọn WCF Server Application

cc

Tạo ServiceContract (Interface trong C#)

IbankService.cs

namespace WcfBankService

{

[ServiceContract]

public interface IBankService

{

[OperationContract]

bool Register(string accId, string name, float balance, string pin);

[OperationContract]

bool ValidateAccount(string accId, string pin);

[OperationContract]

bool WithDraw(string accId,float balance);

[OperationContract]

bool Deposit(string accId,float balance);

[OperationContract]

float ViewBalance(string accId);

}

}

Tạo BankService.cs implement IBankService

namespace WcfBankService

{

public class BankService : IBankService

{

public bool Register(string accId, string name, float balance, string pin)

{

//Viet code them mot hang account

return true;

}

public bool ValidateAccount(string accId, string pin)

{

//Login – Check ID & PIN

return true;

}

public bool WithDraw(string accId, float amount)

{

//Rut tien

//Update Accounts set Balance = Balance-amount

return true;

}

public bool Deposit(string accId, float amt)

{

//Bo tien vao

//Update Accounts set Balance = Balanece + amt

return true;

}

public float ViewBalance(string accId)

{

float balance = 0;

//Kiem tra so du cua tai khoan accit

return balance;

}

}

Giao diện các class sau khi hoàn thiện

21

 

 

7 bước để tích hợp ckfinder vào ceditor

Các bước để tích hợp CKFinder vào CEditor

1/ Download ckfinder

2/ Download ceditor

3/ copy ckfinder, ceditor vào thư mục con của web site. Ví dụ: myweb/ckfinder, myweb/ceditor

4/ copy 2 file ckeditor.dll, ckfinder.dll vào thư mục Bin của web site

5/ Thay đổi thông tin trong config.ascx trong ckfinder như sau:

public override bool CheckAuthentication()
{

// user logs on your system.

return true;
}

public override void SetConfig()
{
// Paste your license name and key here. If left blank, CKFinder will
// be fully functional, in Demo Mode.
LicenseName = “”;
LicenseKey = “”;

// The base URL used to reach files in CKFinder through the browser.
BaseUrl = “~/Images”; // chỉ ra đường dẫn của thư mục ảnh

}

6/ Add CEditor control vào trang web, ví dụ đặt tên là editor1.

7/ Viết đoạn mã sau vào sự kiện form_load của các trang có dùng ceditor

protected void Page_Load(object sender, EventArgs e)
{
CKFinder.FileBrowser _fb = new FileBrowser();
_fb.BasePath = “ckfinder/”;
_fb.SetupCKEditor(this.editor1);

}

Trên đây là 7 bước để tích hợp CKFinder vào ceditor.

WCF Security

http://wcfsecurity.codeplex.com/wikipage?title=How%20To%20-%20Use%20SQL%20Role%20Provider%20with%20Username%20Authentication%20in %20WCF%20calling%20from%20Windows%20Forms&referringTitle=How%20Tos

http://wcfsecurity.codeplex.com/wikipage?title=How%20Tos&referringTitle=Home

http://www.codeproject.com/Articles/570539/HTTPSplusCommunicationplusinplusWCFplususingplusSe

http://wcfsecurity.codeplex.com/wikipage?title=How%20To%20-  %20Use%20Certificate%20Authentication%20and%20Message%20Security%20in%20 WCF%20calling%20from%20Windows%20Forms