JavaWebService client concrete Raiders

zhaozj2021-02-17  59

As a small bamboo of 9CBS JavawebService, I will still want to write some basic articles about JWS. I have been public and busy. I have been unintentional, so I will drag again. I have seen my plaque. I have asked questions about Java calling WebService. He is determined to write this article to share it. Equipment: JDK1.4.1_02, about this problem, there is no need to say it. ^ _ ^ Java Web Services Developer Pack 1.2 (http://java.sun.com/webservices/downloads/webservicespack.html) My JWSDP installation path is e: /minitool/jwsdp-1.2/, in the article, Not sound. Platform: Microsoft Windows 2000 [Version 5.00.2195]

Full text takes Google's WebService as an example, it provides a development kit, http://www.google.com/apis/download.html, but a lot of WebService will not be like this, just tell you a WSDL (WebService Description Language) file. But this has no essential difference, which also contains such a file Googlesearch.wsdl in Google's development kit. Most WebService clients have developed, I know that the WSDL file is already, but Google needs a licenseKey, because it is just testing, so this limit is only one000 to query 1000 or 2000 times, I forgot, I applied for two, in my C # demonstration site (http://63.210.240.215/rookieport/) used two licenseKey, regarding this C # presentation site and source files see http: //www10.brinkster.com/rookieport/default.aspx. Unfortunately, I can't update this two sites, there is no free lunch in the world! ! ! Ok, the theme of this article is JavawebService instead of C # WebService, after preparing, we have a slight analysis of the WSDL file, this file is mainly description WebService specifically used which data structure (described in Types), which provides Web service function (described in Operation), and the access address of the service (described in Service), about WSDL is not detailed, find time to make up.

In GoogleSearch.wsdl, we see a Dogooglesearch Operation, from the name we can see that this method should be a search service, a parameters describing the Dogooglesearch call: The first parameter is licenseKey, the second parameter is the content to query, the third parameter is the start result page, and the page for multiple pages The function, the fourth parameter is to define the maximum number of records per page, and the back parameters are not very important, where LR is the language type that defines the lookup. If you look for Simplified Chinese, IE / OE is an input and output encoding. Type, default is UTF-8.

Later we go down to see a description of the return type of the doGoogleSearch: type = "typens: GoogleSearchResult" Description The namespace of the data type, we look for GooglesearchResult, you can see that he is a composite type,

This describes the data structure of GooglesearchResult, with the properties of Type = "XSD: XXX", which also uses two composite type ResulTelementArray, and DirectoryCateGoryArray readers can continue to analyze, these data types will be by JWS The interpreted conversion tool generates the corresponding Java class. The two types of Array ended, which also generated a corresponding ArrayOfxxxxx class before jwsdp1.1, now 1.2 is better, and directly mapped to the Java array. Well, we can enter the first step in the actual operation of the client development. First we need to edit a config file in an XML format, the form is as follows: < Configuration XMLns = "http://java.sun.com/xml/ns/jax-rpc/ri/config"> This indicates the location of the webservice description file, which can be local or remote. The back PackageName illustrates the package name of the generated WebService client file. Put this file in the directory of Googleapi. Step 2, start the console, enter Googleapi directory C: / Googleapi> DIR / W Volume In Drive C Is Win2k Volume Serial Number is 0B73-18E3

Directory of C: / Googleapi

[.] [..] README.txt GoogleAPIDemo.javaGoogleSearch.wsdl APIs_Reference.htmlLICENSE.txt googleapi.jar [javadoc] [dotnet] [soap-samples] [licenses] google.configJavaWebService client Concise Guide to establish a client's .txt Directory C: /> MKDIR Client Executes WSCompile Generate Client Files C: / Googleapi> E: /MINITOOL/JWSDP 1.2/Jaxrpc/bin/wscompile -gen -gen -dclient -keep google.config -genfig -gen parameter tells the compiler to generate WebService The client file, the -d client saves the generated file, and -keep indicates the retained intermediate file. After execution, enter the client / rook / search to see the generated series Java and Java class files.

In the third step, we create a client call file. Find the top ten records containing the cookie's Chinese page, then print the title and URL. Import rook.searcher. *; import java.rmi. *;

public class Searcher {public static void main (String [] args) {try {GoogleSearchPort sport = new GoogleSearchService_Impl () getGoogleSearchPort ();. GoogleSearchResult result = sport.doGoogleSearch ( "OyGtVqM5YRRS7hFXHLWEodMSEbiZlmc9", "rookie", 0, 10, true, "Lang_ZH-CN", True, "Lang_ZH-CN", "UTF-8", "UTF-8"); // The first parameter is licenseKey ResulTelement [] results = result.getresultElements (); for (int idx) = 0; idx Javac-ClassPath E: /Minitool/jwsdp 1.2/jaxrpc/lib/jaxrpc-impl.jar ;. Searcher.java

Step 5, execute. C: / Googleapi / Client> Java -cp E: /minitool/jwsdp-1.2/jaxrpc/lib/jaxrpc-impl.jar; E: /MINITOOL/JWSDP 1.2/jaxrpc/lib/jaxrpc-api.jar; E: /minitool/jwsdp-1.2/jwsdp-shared/lib/jax-qname.jar ;/minitool/jwsdp-1.2/jwsdp-shared/lib/activation.jar ;:/minitool/jwsdp-1.2/jwsdp-shared /LIB/mail.jar ;/minitool/jwsdp 1.2/jwsdp-shared/lib/xsdlib.jar ;/minitool/jwsdp-1.2/saaj/lib/saaj-api.jar ;/minitool/ JWSDP-1.2 / Saaj / Lib / Saaj-Impl.jar; E: /MINITOOL/JWSDP 1.2/jwsdp-shared/lib/commons-logging.jar; E: /MINITOOL/JWSDP 1.2/jaxp/lib/endorsed/ XerceSIMPL.jar; E: /MINITOL/JWSDP 1.2/jaxp/lib/endorsed/Dom.jar ;. Searcher

The full text ended this, taking the basic steps developed by JavaWebService client, I hope to be able to throw the jade! Unknown in the text, please advise: zlyperson@163.net

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

New Post(0)