Remoting and Web service are important technologies in. NET that can be used for distributed system development, but if you have a different platform, you can choose only Web service, but if it is the same platform, you have the choice. In the end, there is also the consideration of the efficiency of the visit, while in the remoting there are three channels HTTP,TCP,IPC, and they are different. The HTTP channel has advantages over the firewall, and the TCP channel often communicates in the LAN, which is much faster than HTTP . The IPC channel is used for inter-process communication of the same machine, and communication does not occupy network resources and is much faster than TCP. In order to actually compare the actual access speed of these four, I wrote a small program with the test. The implementation of this program is simple to access the same object (equivalent to the business layer in the actual project) using remoting three channels and Web Service, and this object implements the time to return the system. It's so simple. If you are not familiar with remoting and Web service, you can also use this example to familiarize yourself with the differences in the way remoting three channels are written and the invocation of Web service.
Here is the program run interface, I use the minimum time measurement in. NET: Ticks (which may be difficult to measure in milliseconds on this computer), to test the time of each invocation and to compare the speed of the access by a number of times the average time is measured. By testing, you can see how fast they have access to the four: Ipc>tcp>http>web Service. (In fact, the remoting HTTP channel and Web service access speed has yet to be compared, with the test of the host has a certain relationship, in my office, a computer as if the Web service access faster than the HTTP channel), you can test it yourself, Or to study a better method.
Using the HTTP Channel
public void Http ()
{
Stopwatch Stopwatch = new Stopwatch ();
Stopwatch.start ();
MyObject MYOBJ = (MyObject) Activator.GetObject (typeof (MyObject), "Http://localhost:9001/MyObject");
Myobj.getservertime ();
Stopwatch.stop ();
LSBHTTP.ITEMS.ADD (stopwatch.elapsedticks);
}
Using the TCP Channel
public void Tcp ()
{
Stopwatch Stopwatch = new Stopwatch ();
Stopwatch.start ();
MyObject MYOBJ = (MyObject) Activator.GetObject (typeof (MyObject), "Tcp://localhost:9002/myobject");
Myobj.getservertime ();
Stopwatch.stop ();
LSBTCP.ITEMS.ADD (stopwatch.elapsedticks);
}
Using the IPC Channel
public void Ipc ()
{
Stopwatch Stopwatch = new Stopwatch ();
Stopwatch.start ();
MyObject MYOBJ = (MyObject) Activator.GetObject (typeof (MyObject), "Ipc://myhost/myobject");
Myobj.getservertime ();
Stopwatch.stop ();
LSBIPC.ITEMS.ADD (stopwatch.elapsedticks);
}
Access Web Service
public void WebService ()
{
Stopwatch Stopwatch = new Stopwatch ();
Stopwatch.start ();
localhost. Service ws = new localhost. Service ();
Usl GetServerTime ();
Stopwatch.stop ();
LSBWEB.ITEMS.ADD (stopwatch.elapsedticks);
}
private void Btnhttp_click (object sender, EventArgs e)
{
Http ();
}
private void Btntcp_click (object sender, EventArgs e)
{
TCP ();
}
private void Btnwebservice_click (object sender, EventArgs e)
{
WebService ();
}
private void Btnipc_click (object sender, EventArgs e)
{
IPC ();
}
Start testing
private void Btnstat_click (object sender, EventArgs e)
{
Int32 times = Int. Parse (Txttimes.text);
Int64 Sum = 0;
Double ave=0;
LsbHttp.Items.Clear ();
LsbIpc.Items.Clear ();
LsbTcp.Items.Clear ();
LsbWeb.Items.Clear ();
for (Int32 i = 0; I < times; i++)
{
Http ();
TCP ();
IPC ();
WebService ();
}
Calculate Average Time
for (Int32 i=0;i<times;i++)
{
Sum + = Int. Parse (Lsbhttp.items[i]. ToString ());
}
Ave = Sum/times;
Txthttp.text = Ave.tostring ();
Sum = 0;
for (Int32 i = 0; I < times; i++)
{
Sum + = Int. Parse (Lsbtcp.items[i]. ToString ());
}
Ave = Sum/times;
Txttcp.text = Ave.tostring ();
Sum = 0;
for (Int32 i = 0; I < times; i++)
{
Sum += int. Parse (Lsbweb.items[i]. ToString ());
}
Ave = Sum / Times;
txtwebservice.text = ave.tostring ();
sum = 0;
for (int32 i = 0; i < times; i+ +)
{
sum += int. Parse (Lsbipc.items[i]. ToString ());
}
Ave = Sum / Times;
txtipc.text = ave.tostring ();
} HttpChannel HttpChannel = new HttpChannel (9001);
ChannelServices.RegisterChannel (Httpchannel,false);
TcpChannel TcpChannel = new TcpChannel (9002);
ChannelServices.RegisterChannel (Tcpchannel,false);
IpcChannel IpcChannel = new IpcChannel ("MyHost");
ChannelServices.RegisterChannel (Ipcchannel,false);
RemotingConfiguration. RegisterWellKnownServiceType (typeof (RemoteObject. MyObject), "MyObject", WellKnownObjectMode.SingleCall);
Console.ReadLine ();
/files/zhang3533/remotingandwebservice.rar
Test Remoting three channel HTTP,TCP,IPC and Web Service access speed (RPM)