First, about the deployment of WCF
The default wshttp-style WCF is easy to deploy, but here's a recommendation to try not to use WCF's configuration files to deploy even though
We are already familiar with the use of configuration files you will find each egg pain problem.
Ii. the deployment of WCF restful
The following is a simple directory:
The main thing is the host code:
Note: Be sure to use the code instead of the configuration file otherwise help page, default return format, and the configuration of the report exception
interface IService classusingSystem;usingSystem.Runtime.Serialization;usingSystem.ServiceModel;usingSystem.ServiceModel.Web;namespaceservices{[ServiceContract] Public InterfaceIService {[Operationcontract,webget (UriTemplate="Test/{name}")] stringGetData (stringname); }} Services service classusingSystem;namespaceservices{ Public classService:iservice { Public stringGetData (stringname) { returnname; }}} How the host initiates the service:usingSystem;usingSystem.Runtime.Serialization;usingSystem.ServiceModel;usingSystem.ServiceModel.Web;usingSystem.ServiceModel.Description;usingServices;namespacehosting{classMainClass { Public Static voidMain (string[] args) { using(Webservicehost host =NewWebservicehost (typeof(Services.service))) {//host. AddServiceEndpoint (typeof (ICalculator), New WebHttpBinding (), "http://127.0.0.1: 9999/");ServiceEndpoint Endpoint= host. AddServiceEndpoint (typeof(Services.iservice),NewWebHttpBinding (),"http://127.0.0.1:9999/"); if(host. description.behaviors.find<webhttpbehavior> () = =NULL) {WebHttpBehavior Httpbehavior=NewWebHttpBehavior (); Httpbehavior.helpenabled=true;//Open the help pageHttpbehavior.defaultoutgoingresponseformat = Webmessageformat.json;//specifies that the return format is "Json"Httpbehavior.defaultbodystyle = Webmessagebodystyle.bare;//Body Message Stylehttpbehavior.automaticformatselectionenabled =false;//whether to return formatting automaticallyEndpoint. Behaviors.add (Httpbehavior);//To add an end point} host. Opened+=Delegate{Console.WriteLine ("The service has been started!"); }; Host. Open (); Console.readkey (); } } }}
usingSystem;
usingSystem.Runtime.Serialization;
usingSystem.ServiceModel;
usingSystem.ServiceModel.Web;
namespaceServices
{
[ServiceContract]
Public Interface IService
{
[OperationContract,WebGet(UriTemplate="Test/{name}")]
string GetData (string name);
}
}
Linux Learning Diary-WCF restful Deployment (iii)