Current Location:Home - News - . NET News
|
|||
Published:2010.08.04 News Sources:admin Views: | |||
Remoting provides a powerful and efficient method of dealing with remote objects, from a structural point of,. NET Remote objects are very suitable for network access to resources, but without processed by SOAP-based WebServices brought problems. . NET Remoting to use than Java's RMI is simple, but difficult than creating a number of Web Service.
In this article, we will create a database to read the content from the remote object. The article also includes a neglected object database backup feature, so that no database can use the reader is still able to use. NET Remoting.
The first step: Creating shared libraries
Click "File" -> "new creation" -> "project", choose to create a C # Library, and named ResumeServerLibrary, then click the OK button. This will create one of our. NET Remote client and server side for communication of "shared command set."
Positive is the complete code, if you want to skip the database access part, you can use the following code to replace the ResumeLoader object:
public class ResumeLoader: System.MarshalByRefObject ( public ResumeLoader () ( System.Console.WriteLine ("New Referance Added!"); )
public Resume GetResumeByUserID (decimal userID) ( return new Resume (1); ) )
Object name space is needed. Keep in mind that, if the name space does not exist System.Runtime.Remoting.Channels.Tcp information, please check the code as above as a reference was added to the System.Runtime.Remoting.dll.
using System; using System.Runtime; using System.Data.SqlClient;
We use the name for the object space is DotNetRemoteTest, the following object is MarshalByRefObject, in which we have created a reference and include the server-side database operations completed all the work required.
namespace DotNetRemoteTest ( public class ResumeLoader: System.MarshalByRefObject ( private SqlConnection dbConnection;
public ResumeLoader () ( this.dbConnection = new System.Data.SqlClient.SqlConnection (); this.dbConnection.ConnectionString = "Data source = GRIMSAADO2K; initial catalog = underground; integrated security = SSPI; pers" + "Ist security info = True; workstation id = GRIMSAADO2K; packet size = 4096"; / * Specific connection string will be different, this is outside the scope of this article. If you do not know how to create a database connection, use another version of this object. * / System.Console.WriteLine ("New Referance Added!"); )
public Resume GetResumeByUserID (decimal userID) ( Resume resume = new Resume (); try ( dbConnection.Open (); SqlCommand cmd = new SqlCommand ( "SELECT ResumeID, UserID, Title, Body FROM Resume as theResume WHERE theResume.UserID =" + userID + "" , DbConnection ); SqlDataReader aReader = cmd.ExecuteReader (); if (aReader.Read ()) ( resume.ResumeID = aReader.GetDecimal (0); resume.UserID = aReader.GetDecimal (1); resume.Title = aReader.GetString (2); resume. |
|||
This Paper Is Divided Into 1 Page | |||
|
|||