First WebService
Recently, I tried to call someone else’s interface in my project, but found that the way this interface document is very strange, because of the following? WSDL, and then follow the WSDL little root that leads me to the big tree of WebService.
What is the WebService
www.cnblogs.com/sandswitch/… Recommend this blog, write very detailed, easy to understand, webservice is the two systems of remote calls, because now more and more software functions requires that we make it, a single software have already can’t meet our requirements, so we need to call other people’s information, but very trouble and time-consuming to write their own code, So webService appeared, we only need a few lines of code, we can get the information we need remotely in other systems, is really very convenient!
So what exactly does a WebService contain, and how does it differ from our normal interface?
The previous interface is called in the front end, using Ajax, interface is very simple, address/parameter, can be accessed, such an interface is HTTP interface, but now this interface, with our previous interface is not quite the same, as shown in the following figure: interface behind no direct method, but “? WSDL “is the WebService interface, so what’s the difference? Take a look at this blog I recommend… www.cnblogs.com/leeego-123/…
So how do we need to call the webService interface?
(Subchild of interface in document ↓↓↓)
How do I invoke the WebService interface
The following methods are available: 1. Use wsimport/ CXF to generate client code and invoke local interfaces and methods.
2. Call it through client programming
3. Call through Ajax (JS +XML)
4. Call through URLConnection
The specific details can be seen in the first blog I recommend, which is very detailed. I just tried two methods and my ability is limited, so I will not repeat them here. I’ll focus on one approach that I’ve had success with: the first approach, which generates client code through CXF and then calls local interfaces and methods to return data.
Webservice generates client-side code to invoke interfaces and tests
1. Download the apache CXF package, such as apache CXF – 3.2.4, address cxf.apache.org/download.html
(Photo from someone else’s blog: ↓↓)
2. Decompress apache-cxF-3.2.4. zip to a directory eg__ D:\soft_install_work\ apache-cxF-3.2.4
3. Set the environment variable 3.1 CXF_HOME=D:\ apache-CXF-2.7.10 3.2 Add %CXF_HOME%/bin after path;
4. Run the WSdL2Java tool in CMD
Enter wsdL2Java in CMD. If usage is displayed, the configuration is successful
5. Enter wsdL2Java -d d :\ src-client in the CMD commandAPI. XXX. Cn / * * * * / servic…
Where D:\ SRC is the path you want to save to your own project
API. XXX. Cn / * * * * / servic…It’s the interface that the receiver gives you
At this point, the WSDL code can be generated in the D:\ SRC path
In the project :(note that this is generated client code, not source code)
6. Test interface:
The code is as follows, similar to our daily call interface, and call method, is as their own interface method can be.
According to the interface documentation, interfaces are orange boxes, methods are pink boxes, and parameters are blue boxes.
so
1. Instantiate the interface
2. The instantiation SyncAllDataServicePortType (contains the class method), and copy the interface. GetPortType
3. Call the method and write parameters in parentheses.
4. Print the returned XML/JSON file
Webservice interface for the first time, if there is any incorrect, please also criticize and correct.