? The job used a Web Service, but not very familiar with this piece, decided to take the time to learn, now record the most basic point of entry knowledge.
Use Java to build the Web service server and invoke the interface using a Python script.
One, the Web service server side
1. Create a new Java project in Eclipse and create a new test. TestWebService class
Package Test;import Javax.jws.webservice;import Javax.xml.ws.Endpoint, @WebServicepublic class TestWebService {public String SayHello (string name) {return "Hello," + name;} public static void Main (string[] args) {endpoint.publish ("Http://localhost:9999/Service/TestWebService", new TestWebService ());}}
2. Run the main function
3. Access interface
Open the browser and go to http://localhost:9999/Service/TestWebService?wsdl
This xml file does not appear to have any style information associated with it. The document tree is shown below.<!-- Published by JAX-WS RI (http://jax-ws.java.net). ri ' S version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><!-- Generated by JAX-WS RI (http://jax-ws.java.net). ri ' S version is jax-ws ri 2.2.9-b130926.1035 svn-revision# 5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><definitions xmlns:wsu= "/http Docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd " xmlns:wsp=" http://www.w3.org /ns/ws-policy " xmlns:wsp1_2=" Http://schemas.xmlsoap.org/ws/2004/09/policy " xmlns:wsam="/HTTP/ Www.w3.org/2007/05/addressing/metadata " xmlns:soap=" http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns=" http://test/" xmlns:xsd=" Http://www.w3.org/2001/XMLSchema " xmlns=" http ://schemas.xmlsoap.org/wsdl/" targetnamespace=" http://test/" name=" Testwebserviceservice ">< Types><xsd:schema><xsd:import namespace= "http://test/" schemalocation= "http://localhost : 9999/service/testwebservice?xsd=1 "/></xsd:schema></types><message name=" SayHello "> <part name= "Parameters" element= "Tns:sayhello"/></message><message name= " Sayhelloresponse "><part name=" parameters " element=" Tns:sayhelloresponse "/></message> <porttype name= "TestWebService" ><operation name= "SayHello" ><input wsam:action= " Http://test/TestWebService/sayHelloRequest " message=" Tns:sayhello "/><output wsam:action=" http ://test/testwebservice/sayhelloresponse " message=" Tns:sayhelloresponse "/></operation></ Porttype><binding namE= "testwebserviceportbinding" type= "Tns:testwebservice" ><soap:binding transport= "http// Schemas.xmlsoap.org/soap/http " style=" document "/><operation name=" SayHello "><soap:o peration soapaction= ""/><input><soap:body use= "literal"/></input><output> <soap:body use= "literal"/></output></operation></binding><service name= " Testwebserviceservice "><port name=" Testwebserviceport " binding=" tns:TestWebServicePortBinding " ><soap:address location= "Http://localhost:9999/Service/TestWebService"/></port></ Service></definitions>
Second, Python calls
1. Create a Python script and type the following code:
#!/usr/bin/python#-*-coding:utf8-*-from suds.client Import clienturl = "http://localhost:9999/Service/ TESTWEBSERVICE?WSDL "client = Client (URL) #调用Service方法传入参数print client.service.sayHello (" Huangjia ")
2, execute the Python script, you can see the output:
Hello,huangjia
Description
We use Java to provide a Web service interface, provide a SayHello () method, and receive a string type parameter. Using Python to invoke the SayHello () method of the Web service, a cross-service, cross-language call was completed.
This article address: network > WEB Service Learning Server building and client calls
Service-side building and client invocation of WEB service Learning