What is Hessian?
Hessian is a binary web service protocol developed by Caucho. Supports all popular development platforms.
What can Hessia do?
Hessian is used to implement web services.
What are the advantages of Hessia?
The Hessian protocol is similar to the SOAP protocol commonly used by web services. It also encapsulates protocol packets in HTTP packets and transmits them through HTTP channels. Therefore, the Hessian Protocol has the same advantages as the SOAP protocol, that is, transmission is not restricted by the firewall (the firewall usually does not limit the HTTP channel ). The advantages of Hessian protocol are that it uses binary encoding, so the amount of data transmitted is much smaller than that of SOAP protocol. Practice has proved that the volume of data transmitted by Hessian protocol is an order of magnitude less than that of SOAP protocol for transmitting the same object. Therefore, distributed applications in complex network environments can use the Hessian protocol to achieve better performance and reliability.
How to Use Hessian?
Hessian is very simple to use, first go to Hessian official website to download http://hessian.caucho.com/, Hessian support all popular development languages, select net C # Version Download. Hessian is an open-source project whose open-source implementation adopts Apache license. After the download, we will first establish the server:
Create a vs web project and delete the default. aspx file. Reference hessiancsharp. DLL to create an iservice. CS interface. The Code is as follows:
using System;using System.Collections;namespace HessianService{ public interface IService { string Hello(string name); }}
There is nothing to say about the "hello" method. Next we will implement this interface service. CS:
Using system; using system. collections; using hessiancsharp. server; namespace hessianservice {public class service: chessianhandler, iservice {iservice member # region iservice member Public String Hello (string name) {return "hello" + name ;}# endregion }}
Note that the service implementation must inherit the chessianhandler class, which inherits ihttphandler.
OK. Is the code simple enough? But now this service cannot provide external services. We need to make a small configuration for it.
Open Web. config and add the following code in <system. Web>:
<webServices> <protocols> <remove name="HttpPost"/> <remove name="HttpGet"/> </protocols> </webServices>
It's easy to configure ihttphandler.
OK, this is the success of our server!
Start the client below:
Create a console project client and copy the server-side interface iservice.
Modify program. CS:
Using system; using system. collections; using hessiancsharp. client; using hessianservice; namespace client {class clientmain {[stathread] Static void main (string [] ARGs) {chessianproxyfactory factory = new chessianproxyfactory ("username", "password "); string url = "http: // localhost: 36955/hessiantest. hessian "; // modify it to your server address iservice test = (iservice) factory. create (typeof (iservice), URL); string result = test. hello ("Flying Fish"); console. writeline (result); console. readline ();}}}
OK! The client is complete.
Create a Service proxy on the client through chessianproxyfactory and iservice. Then you can use it like a local object. Is it simple enough?
Run the server, modify the URL to your server address, and run the client. You can see "Hello flying fish" in the dark.
My Hessian trial is really good. It is easy to develop and call, and the efficiency is much higher than that of WebService. I have not tested it. If you are interested, you can test it. In addition, the biggest feature is the good cross-platform performance. In some operations that return entities, if the server and the client are not a platform, it does not matter as long as the namespace and attribute names are the same, it is convenient to call.
There are a lot of information about hessiancsharp on the Internet, but there is a lot of difference in configuration. At the beginning, I found some information on Google just one morning, shared out hope that useful friends do not take some detours. Also give you a forum on hessiancsharp: http://www.hessiancsharp.org/forum/
Code: Download source code
Supplement: when deploying IIS, you need to re-configure IIS by right-clicking the site or virtual directory --> main directory ---> configuring to insert wildcards "C: \ WINDOWS \ Microsoft. net \ framework \ v2.0.50727 \ aspnet_isapi.dll "removed" check whether the file has the option "; otherwise, it cannot be called. Click OK.