my_rob
发贴: 3
积分: 0
|
于 2005-10-14 13:30
在调用call.invoke时出错 invoke的原型 public response Call.invoke(java.net.URL url, java.lang.String SOAPActionURI);
查资料有注释: note that the action URI is empty because the XML-SOAP rpc router does not need this. This may change in the future 不知道现在这个URI要怎么写?
设定 SOAPActionURI="urn:getMessage" 问题依然如故
环境 windowsXP console jdk 1.4 tomcat 5.0.28 soap 2.3.1
// HelloWorldService.java public class HelloWorldService { static String str = "Hello World!"; public String getMessage() { return str; } }
// HelloWorldClient.java
import org.apache.soap.Constants; import java.net.URL; import org.apache.soap.Fault; import org.apache.soap.rpc.Call; import org.apache.soap.rpc.Response; import org.apache.soap.rpc.Parameter;
public class HelloWorldClient { static String DEFAULT_ENDPOINT = "http://localhost:8080/soap/servlet/rpcrouter"; public static void main(String args[]) throws Exception { String endPoint = DEFAULT_ENDPOINT;
// Process Arguments System.out.println("Arguments"); if (args.length == 1) { endPoint = args[0]; } else if (args.length > 1) { System.out.println("java HelloWorldClient [endpoint]"); }
// Build the SOAP RPC request message using the Call object System.out.println("Build the SOAP RPC request message"); Call call = new Call(); call.setTargetObjectURI("urn:HelloWorldService"); call.setMethodName("getMessage"); call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
// Create a URL object, which represents the endpoint System.out.println("Create URL"); URL url = new URL(endPoint);
// Send the SOAP RPC request message using invoke() method System.out.println("Send the SOAP RPC request message"); Response resp = call.invoke(url, "");
// Check the response System.out.println("Check repsonse"); if (resp.generatedFault()) { Fault fault = resp.getFault(); System.out.println("The Following Error Occured:"); System.out.println(" Fault Code = " + fault.getFaultCode()); System.out.println(" Fault String = " + fault.getFaultString()); } else { Parameter result = resp.getReturnValue(); System.out.println(result.getValue()); } } }
运行信息:见图
|