soap初学者诚心请教!散分。谢谢!
我在实现一个简单的soap服务时遇到了困难。首先在tomcat上成功配置了apache-soap(把activation.jar,mail.jar,xerces.jar拷贝到了<tomcat_home>/common/lib下,把<soap_home>/webapps下的soap.war拷贝到了<tomcat_home>/webapps下),访问http://localhost:8080/soap时能成功显示页面。
classpath=C:\j2sdk1.4.2\lib;C:\Tomcat 5.0\bin;C:\Tomcat 5.0\common\lib\xerces.ja
r;C:\Tomcat 5.0\common\lib\soap.jar;C:\soap-2_3_1\lib\soap.jar;C:\Tomcat 5.0\com
mon\lib\mail.jar;C:\Tomcat 5.0\common\lib\activation.jar
然后写了个简单的soap服务类:
HelloService.java:
package mypack;
public class HelloService {
public String sayHello(String username) {
return "Hello:"+username;
}
}
编译后把HelloService.class文件拷贝到了<tomcat_home>/webapps/soap/WEB_INF/classse/mypack下。
然后成功发布了此web服务,在命令行中执行java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter query urn:helloservice后,显示:
<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment" id="urn:helloservice" checkMustUnderstands="false">
<isd:provider type="java" scope="Application" methods="sayHello">
<isd:java class="mypack.HelloService" static="false"/>
</isd:provider>
</isd:service>
然后写一个soap客户程序:
HelloClient.java:
package mypack;
import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
public class HelloClient {
public static void main(String[] args)throws Exception {
URL url = new URL ("http://localhost:8080/soap/servlet/rpcrouter");
String username="Guest";
if(args.length!=0) username=args[0];
// Build the call.
Call call = new Call();
call.setTargetObjectURI("urn:helloservice");
call.setMethodName("sayHello");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
Vector params = new Vector();
params.addElement(new Parameter("username", String.class, username, null));
call.setParams (params);
// make the call: note that the action URI is empty because the
// XML-SOAP rpc router does not need this. This may change in the
// future.
Response resp = call.invoke(url, "" );
// Check the response.
if ( resp.generatedFault() ) {
Fault fault = resp.getFault();
System.out.println("The call failed: ");
System.out.println(" Fault Code = " + fault.getFaultCode());
System.out.println(" Fault String = " + fault.getFaultString());
}
else {
Parameter result = resp.getReturnValue();
System.out.println(result.getValue());
}
}
}
编译后,运行:java HelloClient rrr
报错:Exception in thread "main" java.lang.NoClassDefFoundError: HelloClient
请问是怎么回事啊?困扰很久了。谢谢!