Linux Learning Diary-WCF restful Deployment (iii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.