Tomcat Web Service Development Raiders

zhaozj2021-02-16  46

Tomcat Web Service Development Raiders

Welcome everyone to communicate with me: Xiaobai enhydra_boy@tom.com

Welcome to reprint, please keep this statement, thank you!

With the rise of Web computing technologies represented by .NET and J2EE, Web Service has become an increasingly important application. Web service provides a new type of switching method for integration between application systems, .NET, J2EE Support for Web Service Applications.

The author does not want to discuss and explain the Web Service concept and theory. You can further understand from the relevant information below.

Web service conceptual architecture

Http://www-900.ibm.com/developerWorks/cn/webservices/ws-wsca/index.shtml

XML Web Service

http://msdn.microsoft.com/webservices/

Currently, Web Service Application generally uses SOAP (Simple Object Protocol, ie simple object access protocol) protocol, and SOAP has the following advantages over traditional DCOM / COM, CORBA:

First, the former is a 2-way flow-based data exchange, while SOAP is exchanged based on XML-based text data, so it is easier and more convenient in data exchange. Debugging is easier to use SOAP-based applications.

Second, SOAP adopts HTTP protocol, not a private agreement, so it can cross the firewall more secure. Today, Microsoft, IBM, and Sun have added support for SOAP protocols in their respective products, so it is not worth mentioning compared with the former COM / DCOM, CORBA and SOAP. It is the appearance of SOAP, making the collaboration of systems with different architecture technologies, interacting.

SOAP is a new type of distributed computing technology. With SOAP, in conjunction with other technologies, such as UDDI (Universal Discovery Description, And Integration), and WSDL (Web Services Description Language), you can implement future business applications to communicate with web.

So, then let me enter the topic, talk about Tomcat, how to quickly develop Web Service applications.

First, to build an environment, the environment that the author is: windows2000 server (Chinese version) Tomcat4

1 Download Tomcat4, install, and configure it from http://jakarta.apache.org/. Start Tomcat4 and enter http: // localhost: 8080 in the browser. You can see the page, indicating that Tomcat4 has been configured.

2 Download AXIS from http://xml.apache.org/dist/axis/1_1rc1/, unzip down to $ Tomcat_home / WebApps / Axis.

Run http: // localhost: 8080 / axis / index.html in the browser, whether the test can run. Next, we began to develop a Web Service application. Edit a Java file CalcService.java

Public class cagcservice {

Public Int Add (Int P1, INT P2) {

RETURN P1 P2;

}

Public int subtract (int p1, int p2) {

RETURN P1 - P2;

} Copy CalcService.java files to $ Tomcat_Home / WebApps / Axis directory, renamed CALCSERVICE.JWS. In the browser, enter http: // localhost: 8080 / axis / calcservice.jws, get the prompt information as follows: AXIS After packaging the CalcService.jws, it provides a WSDL interface exposed information. You can enter http: // localhost: 8080 / axis / calcservice.jws? WSDL to view the WSDL interface information. With the WSDL interface, we can write a VB program to call. The test steps are as follows: 1 Download SOAP Toolkit 3.0, install it from http://www.microsoft.com. 2 VB6 newly built a project, add a Form, the interface interface is as follows. 3 Write the following code in two buttons cmdadd and cmdminus, respectively.

Private sub cmdadd_click ()

'Test the Add method

ON Error ResMe next

Dim SoapClient As Object

Set soapclient = creteObject ("mssoap.soapclient30")

Call SoapClient.msoapinit 2 (Text1.Text, "," "" "" "CalcService", "" "

IF Err.Number <> 0 THEN

Msgbox soapclient.faultstring, vbexclamation

EXIT SUB

END IF

'Now the client can call an operation listed in the porttype element

'specified when caling mssoapinit ().

TEXT4.TEXT = CSTR (SOAPCLIENT.ADD (Val (Text2.Text), Val (Text3.Text)))))

IF Err.Number <> 0 THEN

Msgbox soapclient.faultstring, vbexclamation

EXIT SUB

END IF

End Sub

Private sub cmdminus_click ()

'Test Substract Method

ON Error ResMe next

Dim SoapClient As Object

Set soapclient = creteObject ("mssoap.soapclient30")

Call SoapClient.msoapinit 2 (Text1.Text, "," "" "" "CalcService", "" "

IF Err.Number <> 0 THEN

Msgbox soapclient.faultstring, vbexclamation

EXIT SUB

END IF

'Now the client can call an operation listed in the porttype element

'specified when caling mssoapinit ().

TEXT7.TEXT = CSTR (SOAPCLIENT.SUBTRACT (Val (Text5.Text), Val (Text6.Text))))

IF Err.Number <> 0 THEN

Msgbox soapclient.faultstring, vbexclamation

EXIT SUBEND IF

End Subs need to be noted that the MSSOAPINIT2 method is simply as follows:

HRESULT MSSOAPINIT2 (

[in] Variant Par_wsdlfile,

[in] Variant Par_wsmlfile,

[in] BSTR PAR_SERVICENAME,

[in] BSTR PAR_PORT,

[in] BSTR PAR_NAMESPACE);

PAR_WSDLFILE WSDL file location, this example is http: // localhost: 8080 / axis / calcservice.jws? WSDLPAR_WSMLFILE This example is an empty PAR_SERVICENAME in this example for an empty PAR_PORT service port number, which can be found from the WSDL file.

PAR_NAMESPACE This example is an empty detailed description of Microsoft Soap Toolkit 3.0, I will introduce the article specifically. 4 Run and test. Summary, apply Web Service technology, we have seen it, you can enjoy Java technology using a program written in VB, and of course you can enjoy .NET technology, of course, the application of VB6 or .NET developed WebService. The application of this technology must bring a new change to the structural mode of the information system.

转载请注明原文地址:https://www.9cbs.com/read-23641.html

New Post(0)