ArticleDirectory
- Create the C ++ header file (Calc. h) to be released)
- Generate the corresponding file through the header file
- Copy soapcpp2.exe from gsoap_win32_2.7.6c.zipto the directory where the header file (Calc. h) is located, and execute soappcpp2.exe Calc. h In the command line.
- The following file will be generated:
- Code compilation through VC ++ 6.0
- Create a project (wt_pro_proj)
- Copy the generated file to the root directory of the project in the same way as stdsoap2.h and stdsoap2.cpp in gsoap_win32_2.7.6c.zip:
- Add the files in the figure to the project:
- Add wsock32.lib to the project:
- Soapc. cpp, soapserver. cpp, and stdsoap2.cpp are not precompiled.
- Create the implementation source file calcserver. cpp for the header file (Calc. h)
- After the compilation is successful, an executable file named by project name (wt_pro_proj.exe) will be generated under the debugdirectory of the target)
- Run wt_pro_proj.exe 9000 in the command line to release the C ++ service. Note that 9000 is the port number. You can specify any unused port number.
-
Java (client) calls the C ++ function released by gsoap (server)
- Server
- Create the C ++ header file (Calc. h) to be released)
-
// Gsoap NS service name: calc
// Gsoap NS service style: RPC
// Gsoap NS service encoding: encoded
// Gsoap NS service namespace: http: // localhost/Calc. WSDL
// Gsoap NS service location: http: // localhost/Calc. cgi
// Gsoap NS schema namespace: urn: calc
Int NS _ add (double num1, double num2, double * sum );
-
Note:
-
Service name: name of the provided service
-
Service style: Web Service binding type, which corresponds
<Binding name = "calc" type = "TNS: calcporttype">
<Soap: Binding style ="RPC"Transport =" http://schemas.xmlsoap.org/soap/http "/>
<Operation name = "add">
<Soap: Operation Style = "RPC" soapaction = ""/>
<Input>
<Soap: body parts = "Parameters" use = "literal" namespace = "urn: calc"/>
</Input>
<Output>
<Soap: body parts = "Parameters" use = "literal" namespace = "urn: calc"/>
</Output>
</Operation>
</Binding>
-
Service encoding: the encoding format, which corresponds to <? XML version = "1.0" encoding = "UTF-8"?>
-
Service namespace: namespace, corresponding to targetnamespace and xmlns: TNS values in WSDL
Targetnamespace = "http: // localhost/Add. WSDL"
Xmlns: TNS = "http: // localhost/Add. WSDL"
-
Service Location: Service Location
<Service name = "calc">
<Documentation> gsoap 2.7.6c generated service definition </documentation>
<Port name = "calc" binding = "TNS: calc">
<Soap: address location = "http: // localhost/Calc. cgi"/>
</Port>
</Service>
-
Schema namespace:
- Generate the corresponding file through the header file
- Copy soapcpp2.exe from gsoap_win32_2.7.6c.zipto the directory where the header file (Calc. h) is located, and execute soappcpp2.exe Calc. h In the command line.
- The following file will be generated:
-
- Compile with VC ++ 6.0 Code
- Create a project (wt_pro_proj)
- Copy the generated file to the root directory of the project in the same way as stdsoap2.h and stdsoap2.cpp in gsoap_win32_2.7.6c.zip:
- Add the files in the figure to the project:
- Add wsock32.lib to the project:
- Soapc. cpp, soapserver. cpp, and stdsoap2.cpp are not precompiled.
- Create the implementation source file calcserver. cpp for the header file (Calc. h)
-
# Include "Calc. H"
# Include "Calc. nsmap"
Int main (INT argc, char * argv [])
{
Int M, s;/* master and slave sockets */
Struct soap calc_soap;
Soap_init (& calc_soap); // soap_set_namespaces (& calc_soap, add_namespaces );
If (argc <2)
{
Printf ("Usage: % S <server_port> \ n", argv [0]);
Exit (1 );
}
Else
{
M = soap_bind (& calc_soap, null, atoi (argv [1]), 100 );
If (M <0)
{
Soap_print_fault (& calc_soap, stderr );
Exit (-1 );
}
Fprintf (stderr, "socket connection successful: Master socket = % d \ n", M );
For (;;)
{
S = soap_accept (& calc_soap );
If (S <0)
{
Soap_print_fault (& calc_soap, stderr );
Exit (-1 );
}
Fprintf (stderr, "socket connection successful: slave socket = % d \ n", S );
Soap_serve (& calc_soap); // describe the Server Service
Soap_end (& calc_soap );
}
}
Return 0;
}
// The server-side implementation function is the same as the function declared in Add. h, but the current SOAP connection parameter is added.
Int NS _ add (struct soap * calc_soap, double num1, double num2, double * sum)
{
* Sum = num1 + num2;
Return 0;
}
- After the compilation is successful, an executable file named by project name (wt_pro_proj.exe) will be generated under the debugdirectory of the target)
- Run wt_pro_proj.exe 9000 in the command line to release the C ++ service. Note that 9000 is the port number. You can specify any unused port number.
- Test, enter http: // localhost: 9000 in the browser
- Client
- 1
- 1
-
11: 47 | Write logs
Please wait... Sorry, the comment you entered is too long. Please shorten your comments. You have not entered anything. Please try again. Sorry, we cannot add your comment currently. Try again later. To add a comment, your parent must grant you the relevant permissions. Your parent has disabled the comment feature. Sorry, we cannot delete your comment currently. Try again later. You have exceeded the maximum number of comments allowed in one day. Please try again in 24 hours. Because our system indicates that you may be providing spam comments to other users, your account has disabled the comments feature. If you believe that your account is incorrectly disabled, contact the Windows Live Support Department. The following security check can be completed only when you provide comments.
The characters you typed in the security check must be the same as those in the image or audio.
To add comments, use your Windows Live ID to log on (if you have used Hotmail, messenger, or Xbox Live, you have a Windows Live ID ). Login
Are there any Windows Live IDs? Please register
Reference announcement