The introduction of WCF integrates. Net remoting, WebService, and so on. It simplifies the communication development on the Microsoft platform and is expected to be the integration direction of the communication processing on the Microsoft platform.
[Simplified configuration]
I may remember that the configuration in WCF 3.0 is indeed complex enough. However, Microsoft has released some streamlined configuration methods in this 4.0 release.
For example, if we want to host a serviceCodeIs it much more convenient?
1.0 "?>
v4.0 " SKU = "
. netframework, version = v4.0 "/>
true "/>
wshttpbinding " Scheme = "
HTTP "/>
----
Webservicehost host =NewWebservicehost (Typeof(Echoservice ),NewUri ("Http: // localhost: 8080/echoservice"); Host. open (); console. writeline ("Press any key to stop this service."); Console. readkey (); host. Close ();
[Webget support]
For convenient webget support, you only need to make a few changes in servicecontract. For example:
[Servicecontract]Public InterfaceIecho {[operationcontract, webget (uritemplate ="Echo/{input}")]StringEcho (StringInput);} so that you can use http: // serviceaddress/Echo/Inputvalue.
[Message format control]
If you want to return JSON or text? 1. Define servicecontract
[Operationcontract]
Message getuser1 (string count );
2. Implement services
PublicSystem. servicemodel. channels. Message getuser1 (StringCount) {list <userinfo> result = getuser (count); weboperationcontext. Current. outgoingresponse. contenttype ="Application/JSON";ReturnWeboperationcontext. Current. createjsonresponse <list <userinfo> (result );}
The JSON format is returned. Of course, there are other formats for convenient support.
[Webfaultexception]
You can easily throw such an error, and the browser will receive the HTTP 400 bad request message.
Throw NewWebfaultexception <String> ("Format Error", System. net. httpstatuscode. badrequest );