1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import javax.xml.namespace.QName; import javax.xml.rpc.Call; import javax.xml.rpc.ParameterMode; import javax.xml.rpc.Service; import javax.xml.rpc.ServiceFactory; import javax.xml.rpc.encoding.XMLType; public class DIITip { public static void main(String args[]) { try { // Create a service class with no WSDL information. You // still must know something about the WSDL, however: the // service's name. QName serviceName = new QName( "http://www.xmethods.net/sd/BNQuoteService.wsdl", "BNQuoteService"); ServiceFactory factory = ServiceFactory.newInstance(); Service service = factory.createService(serviceName); // Now create a dynamic Call object from this service. // This call object is not yet associated with any // operation. We'll do that below. Call call = service.createCall(); // Next, build up the information about the operation... // The operation name QName operationName = new QName( "urn:xmethods-BNPriceCheck", "getPrice"); call.setOperationName(operationName); // The input parameter call.addParameter( "isbn", // parameter name XMLType.XSD_STRING, // parameter XML type QName String.class, // parameter Java type class ParameterMode.IN); // parameter mode // The return call.setReturnType(XMLType.XSD_FLOAT); // The operation is an RPC-style operation. call.setProperty( Call.OPERATION_STYLE_PROPERTY, "rpc"); // The encoding style property value comes from the // binding's operation's input clauses encodingStyle // attribute. Note that, in this case, this call is not // really necessary - the value we're setting this // property to is the default. call.setProperty( Call.ENCODINGSTYLE_URI_PROPERTY, "http://schemas.xmlsoap.org/soap/encoding/"); // The target endpoint call.setTargetEndpointAddress( "http://services.xmethods.net:80/soap/servlet/rpcrouter"); // Invoke the operation Object[] actualArgs = {"0672324229"}; Float price = (Float) call.invoke(actualArgs); System.out.println("price = " + price); } catch (Throwable t) { t.printStackTrace(); } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |