Here, let's introduce the process of Java calling an instance of WebService.
This project cannot be run because the interface address is not available.
This is just to introduce a process, while leaving your own notes. If you want to learn, you can refer to other people's examples. better.
① Select the project root of SRC, right-click, New--"WebService client
Then enter the address:
http://172.18.100.52:456/hello?wsdl
The WSDL end must be added so that it is a webservice interface.
Finlish. Refresh the project at this time. You can see that the client code is generated under/src/com/tem under Project.
The client is ready to call.
Preparation parameters:
public class pubcontroller extends basemultiactioncontroller{ // Merchant Code private final string merchantid = "M14081916173300001";//ipprivate final String merchantIP = "106.38.40.86";//Verify Keyprivate final string merchantkey = "D82f7b84baabf3989ad6da300ea8dad7";p rivate pubmanager pubmanager;public void Setpubmanager (Pubmanager pubmanager) {this.pubmanager = pubmanager;} private billmanager billmanager;public void setbillmanager ( Billmanager billmanager) {this.billmanager = billmanager;} /** * Merchant Information Enquiry Interface * @param request * @param response * @return * @throws exception */public void getscgduser (Httpservletrequest request, httpservletresponse response) throws exception {appclaSsgeneric<querycustomerrsp> appclass = new appclassgeneric<querycustomerrsp> () ;//parameter//Query condition: Card type String querytype=servletrequestutils.getstringparameter (Request, "querytype");//Query Condition two: The corresponding query number String queryvalue=servletrequestutils.getstringparameter (Request, "QueryValue");try { String svcCont = "<! [cdata[<?xml version=\ "1.0\" encoding=\ "utf-8\"?> "+ " < Querycustomerreq> "+" <QueryValue> "+queryvalue+" </QueryValue> "+" <QueryType> "+querytype+" </QueryType> "+" </QueryCustomerReq> "+"]]> "; servicerequestvo servicerequestvo = new servicerequestvo ("SCVC001" , "T001", Svccont,null); Servicerequestvo.setsvccont (Svccont);//get signature, pass signature String sign = getsign ( SERVICEREQUESTVO); Servicerequestvo serviceRequestvo2=pubmanager.getscgduser (servicerequestvo,sign); String json=xmlstringtojson (Servicerequestvo2.getsvccont (). Replace ("<QueryCustomerRsp>", ""). Replace ("</QueryCustomerRsp>", "")); Querycustomerrsp querycustomerrsp= json.parseobject (Json, querycustomerrsp.class);if ( Servicerequestvo2.getresponse (). Getrspcode (). Equals ("00000")) {appclass.setmessagestatus ( msgstatus.success); Appclass.sett (QUERYCUSTOMERRSP);} Else {appclass.setmessagestatus (Msgstatus.fail); Appclass.setmessage (Servicerequestvo2.getresponse (). Getrspdesc ());}} catch (exception e) {appclass.setmessagestatus (msgstatus.fail); Appclass.setmessage ( E.getmessage ()); E.printstacktrace ();} finally {jsonobject json = jsonobject.fromobject (Appclass); Response.setContentType (" Text/html;charset=utf-8 "); Response.getwriter (). print (JSON); Response.getwriter (). Flush ();}}
Call the WebService interface using locally generated code:
The WebService proxy class generated by the public class Pubmanagerimpl implements pubmanager{//. Native Java code. Pubwebserviceporttypeproxy pubwebserviceporttypeproxy=new pubwebserviceporttypeproxy ();/** * User Information query interface * @throws RemoteException */@Overridepublic servicerequestvo getscgduser (servicerequestvo servicerequestvo,string sign) throws RemoteException {//Call the method in the WebService interface. Return PUBWEBSERVICEPORTTYPEPROXY.SCBSS (servicerequestvo,sign); }
This article is from the "Jianbo" blog, make sure to keep this source http://jianboli.blog.51cto.com/12075002/1887421
Java calls WebService interface instance