The demo server is built by .NET, the client is accessed by the Java program, Web Service builds
Use .NET to build a web service project with .NET, use C # as the programming language. Suppose the code is as follows: use system;
Using system.collections;
Using system.componentmodel;
Using system.data;
Using system.diagnostics;
Using system.Web;
Using system.Web.services;
Namespace Service1.asmx
{
///
/// service1's summary description.
/// summary>
Public class service1: system.web.services.Webservice
{
Public service1 ()
{
// Codegen: This call is necessary for the ASP.NET Web service designer.
InitializationComponent ();
}
#REGION component designer generated code
/ / Web service designer necessary
Private icontainer Components = NULL;
///
/// Designer supports the required method - do not use the code editor to modify
/// This method is content.
/// summary>
Private vidinitiRizeComponent ()
{
}
///
/// Clean all the resources being used.
/// summary>
Protected Override Void Dispose (Bool Disposing)
{
IF (Disposing && Components! = NULL)
{
Components.dispose ();
}
Base.dispose (Disposing);
}
#ndregion
// Web service example
// HelloWorld () sample service Returns Hello World
[WebMethod]
Public String HelloWorld ()
{
Return "Hello World";
}
// Web service example
/ / Calculate the result in the server side by incoming parameters and return
[WebMethod]
Public Int AddVal (Int i, int J)
{
Addlib.mathclass Obj = new addlib.mathclass ();
Return Obj.AddVal (i, j);
}
// Web service example
// Return one-dimensional array
[WebMethod]
Public int [] ReturnInTarr ()
{
Int [] bb = new int [6];
BB [0] = 1;
BB [1] = 2;
BB [2] = 3;
BB [3] = 4;
BB [4] = 5;
BB [5] = 6;
Return BB;
}
// Web service example
// Return to multi-dimensional array
[WebMethod]
Public ArrayList Returnarrs ()
{
ArrayList Al = New ArrayList ();
For (int JJ = 1; JJ <10; JJ ) {
Al.Add (Returnalist (jj));
}
Return Al;
}
Private ArrayList Returnalist (INT i)
{
ArrayList Al = New ArrayList ();
For (int J = 0; j <6; j ) {
Al.Add ("WYL" J);
}
Return Al;
}
// Web service example
// Return to self-build object
[WebMethod]
Public myObject_hhf returnmyobj (INT i)
{
MyObject_hhf myobj = new myObject_hhf (i);
myobj.setval ();
Return myobj;
}
}
// Web service example
// Self-constructive object
[Serializable]
Public class myObject_hhf //: DataSet //: iSerializable
{
Public int m_irowcount;
Public int m_icolcount;
Public INT I;
Public arraylist aryobj = new arraylist ();
Public myObject_hhf ()
{}
Public myObject_hhf (INT i)
{
THIS.I = I;
THIS.M_ICOLCOUNT = i 1;
THIS.M_IROWCOUNT = i 2;
}
Public void setval ()
{
For (int J = 0; j
{
Aryobj.Add (j);
}
}
}
}
The above code exposes 5 interfaces: return strings, one method, one-dimensional array, multi-dimensional array, a self-building object.