WebService series Teaching (4)-How to call WebService (Pb,java)

Source: Internet
Author: User
Tags soap web services
Web 4.1 using PowerBuilder calls
Applicable version 8.0 download Bulletin Web Services Toolkit 4.1
4. 2 using Java Invoke
Need to download Apache soap. Download Address: http://xml.apache.org/soap/index.html
Import:
Import org.apache.soap.*;
Import org.apache.soap.rpc.*;
Routines:
Import java.io.*;
Import java.util.*;
Import java.net.*;
Import org.w3c.dom.*;
Import org.apache.soap.util.xml.*;
Import org.apache.soap.*;
Import org.apache.soap.encoding.*;
Import org.apache.soap.encoding.soapenc.*;
Import org.apache.soap.rpc.*;
Import org.apache.soap.transport.http.SOAPHTTPConnection;

public class TestClient {

public static void Main (string[] args) throws Exception {

URL url = new URL ("http://192.168.0.4/yundan/service1.wsdl");
Change it to your address.
Soapmappingregistry SMR = new Soapmappingregistry ();
Stringdeserializer sd = new Stringdeserializer ();
Smr.maptypes (Constants.ns_uri_soap_enc, New QName ("", "result"), NULL, NULL, SD);

Creating transport paths and parameters
Soaphttpconnection st = new Soaphttpconnection ();

Create call
Call call = new Call ();
Call.setsoaptransport (ST);
Call.setsoapmappingregistry (SMR);

Call.settargetobjecturi ("http://tempuri.org/message/");
Call.setmethodname ("AddNumbers");
Call.setencodingstyleuri ("http://schemas.xmlsoap.org/soap/encoding/");

Vector params = new vector ();
Params.addelement (New Parameter ("Numberone", Double.class, "ten", null));
Params.addelement (New Parameter ("Numbertwo", Double.class, "a", null));
Call.setparams (params);

Response resp = null;

try {
resp = call.invoke (URL, "http://tempuri.org/action/Hello2.addNumbers");
}
catch (SoapException e) {
System.err.println ("Caught SoapException" ("+ e.getfaultcode () +"): "+ e.getmessage ());
Return
}

Check return value
if (resp!= null &&!resp.generatedfault ()) {
Parameter ret = Resp.getreturnvalue ();
Object value = Ret.getvalue ();

System.out.println ("answer-->" + value);
}
else {
Fault Fault = Resp.getfault ();
SYSTEM.ERR.PRINTLN ("Generated fault:");
System.out.println ("Fault Code =" + Fault.getfaultcode ());
System.out.println ("Fault String =" + fault.getfaultstring ());
}
}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.