解决了上面的问题,又出问题了,找是找到我的soap的服务端了,可是返回来的是个FAULT:在客户段打印出来时这样的:Call failed due to a SOAP Fault: 
  Fault Code   = SOAP-ENV:Server.Exception:
  Fault String = org/apache/soap/SOAPException  toString:  [Attributes={}] [faultCode=SOAP-ENV:Server.Exception:] [faultString=org/apache/soap/SOAPException] [faultActorURI=/soap/servlet/rpcrouter] [DetailEntries=] [FaultEntries=]我没看到太多的有帮助的信息,于是修改了服务器段的代码,向日至里输出一些内容,可是不没有被执行,问题出在那里呢,这个异常好像是/soap/servlet/rpcrouter跑出的,我再apache soap admin上部署的参数是这样的: ID - urn:stock-onhand 
Scope - Application 
Provider Type - java 
Provider Class - com.weixin.web_service.soapRpc.StockQuantity 
Use Static Class - false 
Methods - getQty 
      
我的服务器段代码 :
      package com.weixin.web_service.soapRpc;
import org.apache.soap.Constants;
import org.apache.soap.SOAPException;public class StockQuantity{  public int getQty (String item)throws SOAPException {
  
  System.out.println("111111111111");    int inStockQty = (int)(Math.random() * (double)1000);    if (item.equalsIgnoreCase("Fail")){
     System.out.println("Fail----------------");
        throw new SOAPException(Constants.FAULT_CODE_SERVER,"Test Fault");
    }
    System.out.println("22222222222222222222");    return inStockQty;   }}客户段代码:
package com.weixin.web_service.soapRpc;import java.net.*;
import java.util.*;import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;
public class CheckStock {    private static final String DEFAULT_HOST_URL = "http://localhost:8080/soap/servlet/rpcrouter";
    private static final String DEFAULT_ITEM = "Test";
    private static final String URI = "urn:oreilly-jaws-samples";    //Member variables
    private String m_hostURL;
    private String m_item;    public CheckStock (){
        m_hostURL = DEFAULT_HOST_URL;
        m_item    = DEFAULT_ITEM;        System.out.println();
        System.out.println(
            "______________________________________________________");
        System.out.println("Starting CheckStock client:");
        System.out.println("    host url        = " + m_hostURL);
        System.out.println("    item            = " + m_item);
        System.out.println(
            "_______________________________________________________");
        System.out.println();
    }    public void checkStock() throws Exception {      //Build the call.
      Call call = new Call ();      //This service uses standard SOAP encoding
      String encodingStyleURI = Constants.NS_URI_SOAP_ENC;
      call.setEncodingStyleURI(encodingStyleURI);      //Set the target URI
      call.setTargetObjectURI ("urn:stock-onhand");      //Set the method name to invoke
      call.setMethodName ("getQty");      //Create the parameter objects
      Vector params = new Vector ();
      params.addElement (new Parameter("item",String.class, m_item, null));      //Set the parameters
      call.setParams (params);      //Invoke the service
      Response resp = call.invoke ( new URL(m_hostURL),"");      //Check the response
      if (resp != null) {
         if (resp.generatedFault ()){
            Fault fault = resp.getFault ();
            System.out.println ("Call failed due to a SOAP Fault: ");
            System.out.println ("  Fault Code   = " + fault.getFaultCode ());
            System.out.println ("  Fault String = " + fault.getFaultString ());
            System.out.println ("  toString:  " + fault.toString());
            
         } else {
            Parameter result = resp.getReturnValue ();
            Integer intresult = (Integer) result.getValue();
            System.out.println ("The stock-on-hand quantity for this item is: " 
                + intresult );
         }
      }
    }    //
    // NOTE: the remainder of this deals with reading arguments
    //
    /** Main program entry point. */    public static void main(String args[]) {
    
    
              // Start the CheckStock client
        try{
            CheckStock stockClient = new CheckStock();
            stockClient.checkStock();
        }catch(Exception e){
                 e.printStackTrace();
        }
    }
}高手们请费点时间帮忙看看吧,分不够再加的!!!!谢谢啦

解决方案 »

  1.   

    我把你的源代码复制下来,在自己机器上能运行的(为了方便,我用默认包)
    E:\Tomcat 5.0\webapps\soap\WEB-INF\classes>java CheckStock______________________________________________________
    Starting CheckStock client:
        host url        = http://localhost:8080/soap/servlet/rpcrouter
        item            = Test
    _______________________________________________________The stock-on-hand quantity for this item is: 126
    所以你的问题应该是的环境没有配置好,这个apache soap admin有bug的,用它配置是不能成功的。
    下面是我的配置以及发布的过程:
    1、把soap.war复制到%CATALINA_HOME%\webapps下
    2、把activation.jar和mail.jar复制到%CATALINA_HOME%\common\lib下
    3、重启tomcat(自动解压soap.war,%CATALINA_HOME%\webapps自动生成文件夹soap)
    4、classpath设置:
    .;D:\web\apache\xerces-1_4_4\xerces.jar;D:\web\apache\soap-bin-2.3.1\soap-2_3_1\lib\soap.jar;%CATALINA_HOME%\common\lib\activation.jar;%CATALINA_HOME%\common\lib\mail.jar;%CATALINA_HOME%\common\lib\servlet-api.jar;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar
    5、在%CATALINA_HOME%\webapps\soap\WEB-INF\classes建立文件StockQuantity.java,CheckStock.java,编译
    6、发布服务(http://localhost:8080/soap/admin/index.html的Deploy有BUG,使用命令行发布)
    (1)编写deploy.xml
    <isd:service 
       xmlns:isd="http://xml.apache.org/xml-soap/deployment"
       id="urn:stock-onhand" checkMustUnderstands="true">
          <isd:provider type="java" scope="Application" methods="getQty">
          <isd:java class="StockQuantity" static="false"/>
       </isd:provider>
    </isd:service>
    (2)把deploy.xml放到%CATALINA_HOME%\webapps\soap\WEB-INF\classes\org\apache\soap\server
    (3)在命令行中改变目录为%CATALINA_HOME%\webapps\soap\WEB-INF\classes\org\apache\soap\server
    (4)运行java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter deploy deploy.xml
    7、重启tomcat
    8、运行CheckStock
      

  2.   

    更正一下,那个apache soap admin没问题,是我自己不会用。
    用两种方法发布服务都是可以的。