CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  Web Services / XML

急~~怎么调用java的webservice??

楼主freesnower1001(云淡风轻)2005-04-01 18:55:28 在 Java / Web Services / XML 提问

在java里怎么调用我发布的java   web   service??请大家给出一个例子。我的服务器是tomcat5.0  
  之前一直是用c#,目前用c#调用java的web   service有问题,所以我先用java调用一下。请大家给出一个例子,非常感谢! 问题点数:50、回复次数:23Top

1 楼freesnower1001(云淡风轻)回复于 2005-04-01 20:05:48 得分 0

对了,我知道明确的URL,请大家给出一个例子吧,谢谢!Top

2 楼freesnower1001(云淡风轻)回复于 2005-04-01 20:19:33 得分 0

String   wsdlURL   =   http://localhost:6080/HelloWebService/services/Hello?wsdl";  
  String   namespace   =   "http://Hello.com";  
  String   serviceName   =   "HelloWebService";  
  QName   serviceQN   =   new   QName(namespace,   serviceName);  
                   
  ServiceFactory   serviceFactory   =   ServiceFactory.newInstance();  
  Service   service   =   serviceFactory.createService(new   URL(wsdlURL),   serviceQN);  
  然后呢,或者这样做本来就是错误的!  
  Top

3 楼zcjl()回复于 2005-04-01 23:17:20 得分 30

String   endpointURL   =   "http://localhost/axis/services/City?wsdl";  
  String   ns   =   "service.ws.zcjl.com";  
  String   serviceName   =   "CityServiceService";  
  QName   qName   =   new   QName(ns,   serviceName);  
  ServiceFactory   sf   =   ServiceFactory.newInstance();  
  Service   service   =   sf.createService(new   URL(endpointURL),   qName);  
   
  QName   portName   =   new   QName("",   "City");  
  CityService   city   =   (CityService)   service.getPort(portName,   CityService.class);  
  System.out.println(city.getZip());  
   
   
  其中CityService.java如下:  
  package   com.zcjl.ws.service;  
   
  public   interface   CityService   extends   java.rmi.Remote   {  
          public   java.lang.String   getZip()   throws   java.rmi.RemoteException;  
          public   java.lang.String   getTel()   throws   java.rmi.RemoteException;  
  }  
  Top

4 楼freesnower1001(云淡风轻)回复于 2005-04-02 09:59:08 得分 0

QName   portName   =   new   QName("",   "City")中的City可以任意命名嘛?或者这个有什么特殊的含义?谢谢!Top

5 楼zcjl()回复于 2005-04-02 10:06:04 得分 0

String   endpointURL   =   "http://localhost/axis/services/City?wsdl";  
                                                                                                          ******  
   
  就是上面所标出的部署的service   NameTop

6 楼zcjl()回复于 2005-04-02 10:06:53 得分 0

我这个例子是参照  
  http://www-900.ibm.com/developerWorks/cn/webservices/ws-tip-soapjax/index.shtml  
  写的Top

7 楼freesnower1001(云淡风轻)回复于 2005-04-02 10:13:15 得分 0

报了这样一个错误:(  
   
  javax.xml.rpc.ServiceException:   Only   interfaces   may   be   used   for   the   proxy   class   argument  
   
  at   org.apache.axis.client.Service.getPort(Service.java:405)  
   
  at   org.apache.axis.client.Service.getPort(Service.java:312)  
   
  at   b2b.TestWebService.main(TestWebService.java:65)  
   
  Exception   in   thread   "main"Top

8 楼joybo()回复于 2005-04-02 10:23:06 得分 20

例如:现在有一个提供天气预报的webservice服务“http://webservicexx.net/webservice/Weather.asmx?WSDL”  
   
  根据此可以得到Weather.java,WeatherLocator.java,WeatherSoap.java,WeatherSoapStub.java到本地,如下:  
   
  Weather.java:  
  package   net.webservicexx.webservice;  
   
  public   interface   Weather   extends   javax.xml.rpc.Service   {  
          public   java.lang.String   getWeatherSoapAddress();  
   
          public   net.webservicexx.webservice.WeatherSoap   getWeatherSoap()   throws   javax.xml.rpc.ServiceException;  
   
          public   net.webservicexx.webservice.WeatherSoap   getWeatherSoap(java.net.URL   portAddress)   throws   javax.xml.rpc.ServiceException;  
  }  
   
   
  WeatherLocator.java:  
  package   net.webservicexx.webservice;  
   
  public   class   WeatherLocator   extends   org.apache.axis.client.Service   implements   net.webservicexx.webservice.Weather   {  
   
          //   Use   to   get   a   proxy   class   for   WeatherSoap  
          private   final   java.lang.String   WeatherSoap_address   =   "http://webservicexx.net/webservice/Weather.asmx";  
   
          public   java.lang.String   getWeatherSoapAddress()   {  
                  return   WeatherSoap_address;  
          }  
   
          //   The   WSDD   service   name   defaults   to   the   port   name.  
          private   java.lang.String   WeatherSoapWSDDServiceName   =   "WeatherSoap";  
   
          public   java.lang.String   getWeatherSoapWSDDServiceName()   {  
                  return   WeatherSoapWSDDServiceName;  
          }  
   
          public   void   setWeatherSoapWSDDServiceName(java.lang.String   name)   {  
                  WeatherSoapWSDDServiceName   =   name;  
          }  
   
          public   net.webservicexx.webservice.WeatherSoap   getWeatherSoap()   throws   javax.xml.rpc.ServiceException   {  
                java.net.URL   endpoint;  
                  try   {  
                          endpoint   =   new   java.net.URL(WeatherSoap_address);  
                  }  
                  catch   (java.net.MalformedURLException   e)   {  
                          throw   new   javax.xml.rpc.ServiceException(e);  
                  }  
                  return   getWeatherSoap(endpoint);  
          }  
   
          public   net.webservicexx.webservice.WeatherSoap   getWeatherSoap(java.net.URL   portAddress)   throws   javax.xml.rpc.ServiceException   {  
                  try   {  
                          net.webservicexx.webservice.WeatherSoapStub   _stub   =   new   net.webservicexx.webservice.WeatherSoapStub(portAddress,   this);  
                          _stub.setPortName(getWeatherSoapWSDDServiceName());  
                          return   _stub;  
                  }  
                  catch   (org.apache.axis.AxisFault   e)   {  
                          return   null;  
                  }  
          }  
   
          /**  
            *   For   the   given   interface,   get   the   stub   implementation.  
            *   If   this   service   has   no   port   for   the   given   interface,  
            *   then   ServiceException   is   thrown.  
            */  
          public   java.rmi.Remote   getPort(Class   serviceEndpointInterface)   throws   javax.xml.rpc.ServiceException   {  
                  try   {  
                          if   (net.webservicexx.webservice.WeatherSoap.class.isAssignableFrom(serviceEndpointInterface))   {  
                                  net.webservicexx.webservice.WeatherSoapStub   _stub   =   new   net.webservicexx.webservice.WeatherSoapStub(new   java.net.URL(WeatherSoap_address),   this);  
                                  _stub.setPortName(getWeatherSoapWSDDServiceName());  
                                  return   _stub;  
                          }  
                  }  
                  catch   (java.lang.Throwable   t)   {  
                          throw   new   javax.xml.rpc.ServiceException(t);  
                  }  
                  throw   new   javax.xml.rpc.ServiceException("There   is   no   stub   implementation   for   the   interface:     "   +   (serviceEndpointInterface   ==   null   ?   "null"   :   serviceEndpointInterface.getName()));  
          }  
   
          /**  
            *   For   the   given   interface,   get   the   stub   implementation.  
            *   If   this   service   has   no   port   for   the   given   interface,  
            *   then   ServiceException   is   thrown.  
            */  
          public   java.rmi.Remote   getPort(javax.xml.namespace.QName   portName,   Class   serviceEndpointInterface)   throws   javax.xml.rpc.ServiceException   {  
                  if   (portName   ==   null)   {  
                          return   getPort(serviceEndpointInterface);  
                  }  
                  String   inputPortName   =   portName.getLocalPart();  
                  if   ("WeatherSoap".equals(inputPortName))   {  
                          return   getWeatherSoap();  
                  }  
                  else     {  
                          java.rmi.Remote   _stub   =   getPort(serviceEndpointInterface);  
                          ((org.apache.axis.client.Stub)   _stub).setPortName(portName);  
                          return   _stub;  
                  }  
          }  
   
          public   javax.xml.namespace.QName   getServiceName()   {  
                  return   new   javax.xml.namespace.QName("http://webservicexx.net/webservice/",   "Weather");  
          }  
   
          private   java.util.HashSet   ports   =   null;  
   
          public   java.util.Iterator   getPorts()   {  
                  if   (ports   ==   null)   {  
                          ports   =   new   java.util.HashSet();  
                          ports.add(new   javax.xml.namespace.QName("WeatherSoap"));  
                  }  
                  return   ports.iterator();  
          }  
   
  }  
   
  未完待续............................Top

9 楼joybo()回复于 2005-04-02 10:24:17 得分 0

接上...........................  
   
  WeatherSoap.java:  
  package   net.webservicexx.webservice;  
   
  public   interface   WeatherSoap   extends   java.rmi.Remote   {  
          public   java.lang.String   getWeatherInfo(java.lang.String   cityName,   java.lang.String   loginId)   throws   java.rmi.RemoteException;  
  }  
   
  WeatherSoapStub.java:  
  package   net.webservicexx.webservice;  
   
  public   class   WeatherSoapStub   extends   org.apache.axis.client.Stub   implements   net.webservicexx.webservice.WeatherSoap   {  
          private   java.util.Vector   cachedSerClasses   =   new   java.util.Vector();  
          private   java.util.Vector   cachedSerQNames   =   new   java.util.Vector();  
          private   java.util.Vector   cachedSerFactories   =   new   java.util.Vector();  
          private   java.util.Vector   cachedDeserFactories   =   new   java.util.Vector();  
   
          static   org.apache.axis.description.OperationDesc   []   _operations;  
   
          static   {  
                  _operations   =   new   org.apache.axis.description.OperationDesc[1];  
                  org.apache.axis.description.OperationDesc   oper;  
                  oper   =   new   org.apache.axis.description.OperationDesc();  
                  oper.setName("GetWeatherInfo");  
                  oper.addParameter(new   javax.xml.namespace.QName("http://webservicexx.net/webservice/",   "cityName"),   new   javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",   "string"),   java.lang.String.class,   org.apache.axis.description.ParameterDesc.IN,   false,   false);  
                  oper.addParameter(new   javax.xml.namespace.QName("http://webservicexx.net/webservice/",   "loginId"),   new   javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",   "string"),   java.lang.String.class,   org.apache.axis.description.ParameterDesc.IN,   false,   false);  
                  oper.setReturnType(new   javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",   "string"));  
                  oper.setReturnClass(java.lang.String.class);  
                  oper.setReturnQName(new   javax.xml.namespace.QName("http://webservicexx.net/webservice/",   "GetWeatherInfoResult"));  
                  oper.setStyle(org.apache.axis.enum.Style.WRAPPED);  
                  oper.setUse(org.apache.axis.enum.Use.LITERAL);  
                  _operations[0]   =   oper;  
   
          }  
   
          public   WeatherSoapStub()   throws   org.apache.axis.AxisFault   {  
                    this(null);  
          }  
   
          public   WeatherSoapStub(java.net.URL   endpointURL,   javax.xml.rpc.Service   service)   throws   org.apache.axis.AxisFault   {  
                    this(service);  
                    super.cachedEndpoint   =   endpointURL;  
          }  
   
          public   WeatherSoapStub(javax.xml.rpc.Service   service)   throws   org.apache.axis.AxisFault   {  
                  if   (service   ==   null)   {  
                          super.service   =   new   org.apache.axis.client.Service();  
                  }   else   {  
                          super.service   =   service;  
                  }  
          }  
   
          private   org.apache.axis.client.Call   createCall()   throws   java.rmi.RemoteException   {  
                  try   {  
                          org.apache.axis.client.Call   _call   =  
                                          (org.apache.axis.client.Call)   super.service.createCall();  
                          if   (super.maintainSessionSet)   {  
                                  _call.setMaintainSession(super.maintainSession);  
                          }  
                          if   (super.cachedUsername   !=   null)   {  
                                  _call.setUsername(super.cachedUsername);  
                          }  
                          if   (super.cachedPassword   !=   null)   {  
                                  _call.setPassword(super.cachedPassword);  
                          }  
                          if   (super.cachedEndpoint   !=   null)   {  
                                  _call.setTargetEndpointAddress(super.cachedEndpoint);  
                          }  
                          if   (super.cachedTimeout   !=   null)   {  
                                  _call.setTimeout(super.cachedTimeout);  
                          }  
                          if   (super.cachedPortName   !=   null)   {  
                                  _call.setPortName(super.cachedPortName);  
                          }  
                          java.util.Enumeration   keys   =   super.cachedProperties.keys();  
                          while   (keys.hasMoreElements())   {  
                                  java.lang.String   key   =   (java.lang.String)   keys.nextElement();  
                                  _call.setProperty(key,   super.cachedProperties.get(key));  
                          }  
                          return   _call;  
                  }  
                  catch   (java.lang.Throwable   t)   {  
                          throw   new   org.apache.axis.AxisFault("Failure   trying   to   get   the   Call   object",   t);  
                  }  
          }  
   
          public   java.lang.String   getWeatherInfo(java.lang.String   cityName,   java.lang.String   loginId)   throws   java.rmi.RemoteException   {  
                  if   (super.cachedEndpoint   ==   null)   {  
                          throw   new   org.apache.axis.NoEndPointException();  
                  }  
                  org.apache.axis.client.Call   _call   =   createCall();  
                  _call.setOperation(_operations[0]);  
                  _call.setUseSOAPAction(true);  
                  _call.setSOAPActionURI("http://webservicexx.net/webservice/GetWeatherInfo");  
                  _call.setEncodingStyle(null);  
                  _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR,   Boolean.FALSE);  
                  _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS,   Boolean.FALSE);  
                  _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);  
                  _call.setOperationName(new   javax.xml.namespace.QName("http://webservicexx.net/webservice/",   "GetWeatherInfo"));  
   
                  setRequestHeaders(_call);  
                  setAttachments(_call);  
                  java.lang.Object   _resp   =   _call.invoke(new   java.lang.Object[]   {cityName,   loginId});  
   
                  if   (_resp   instanceof   java.rmi.RemoteException)   {  
                          throw   (java.rmi.RemoteException)_resp;  
                  }  
                  else   {  
                          extractAttachments(_call);  
                          try   {  
                                  return   (java.lang.String)   _resp;  
                          }   catch   (java.lang.Exception   _exception)   {  
                                  return   (java.lang.String)   org.apache.axis.utils.JavaUtils.convert(_resp,   java.lang.String.class);  
                          }  
                  }  
          }  
   
  }  
   
   
  然后写测试类如下:  
  package   net.webservicexx.webservice;  
   
  import   java.rmi.*;  
   
  public   class   Test   {  
      public   Test()   {  
      }  
   
      public   static   void   main(String[]   args)   {  
          net.webservicexx.webservice.WeatherSoapStub   binding;  
          try   {  
              binding   =   (net.webservicexx.webservice.WeatherSoapStub)  
                      new   net.webservicexx.webservice.WeatherLocator().getWeatherSoap();  
          }  
          catch   (javax.xml.rpc.ServiceException   jre)   {  
              if   (jre.getLinkedCause()   !=   null)   {  
                  jre.getLinkedCause().printStackTrace();  
              }  
              throw   new   junit.framework.AssertionFailedError(  
                      "JAX-RPC   ServiceException   caught:   "   +   jre);  
          }  
   
          //   Time   out   after   a   minute  
          binding.setTimeout(60000);  
   
          //   Test   operation  
          java.lang.String   value   =   null;  
          try   {  
              value   =   binding.getWeatherInfo("深圳",  
                                                                            "000000002005010100000001");  
              System.out.println("======天气预报======="+value);  
          }  
          catch   (RemoteException   ex)   {  
          }  
   
      }  
  }  
   
  就可以得到天气了!!!Top

10 楼zcjl()回复于 2005-04-02 11:05:32 得分 0

回复人:   freesnower1001(云淡风轻)   (   )   信誉:100     2005-04-02   10:13:00     得分:   0      
     
     
        报了这样一个错误:(  
   
  javax.xml.rpc.ServiceException:   Only   interfaces   may   be   used   for   the   proxy   class   argument  
   
  >>>>  
  错误描述很清楚啊  
  CityService   city   =   (CityService)   service.getPort(portName,   CityService.class);  
  这里的CityService一定得是接口来的(我前面有给出这个代码)  
  因为java的动态代理只支持接口,而不是一般类型Top

11 楼zcjl()回复于 2005-04-02 11:10:18 得分 0

楼上joybo()   的方法是根据WSDL2Java工具,通过已有的wsdl文件来自动生成相应的client接口和stub  
  这也是一种简单易用的办法  
   
  还是比如这个CityService,通过axis的WSDL2Java,可以生成四个类(包括接口):  
  CityService.java  
  CityServiceService.java  
  CityServiceServiceLocator.java  
  CitySoapBindingStub.java  
   
  然后可以在TestCity.java中如此调用  
   
  public   class   TestCity   {  
          public   static   void   main(String[]   args)   throws   Exception   {  
                  CityServiceServiceLocator   loc   =   new   CityServiceServiceLocator();  
                  CityService   cs   =   loc.getCity();  
                  System.out.println("the   zip   code:   "   +   cs.getZip());  
                  System.out.println("the   tel   code:   "   +   cs.getTel());  
          }  
  }  
   
  简单吧?Top

12 楼Jiazi840207(Jiazi)回复于 2005-04-02 12:18:15 得分 0

留名,学习.Top

13 楼freesnower1001(云淡风轻)回复于 2005-04-02 12:48:44 得分 0

不对,我可以把我的这个几个自动生成的类(接口给你看,调用的时候有问题),实在是不好意思啊,java这里几乎一无所知。  
    SimpleTest.java  
  public   interface   SimpleTest   extends   java.rmi.Remote   {  
          public   test.generated.Message   process(test.generated.Message   in0)   throws   java.rmi.RemoteException;  
  }  
   
  SimpleTestServic.java  
  public   interface   SimpleTestService   extends   javax.xml.rpc.Service   {  
          public   java.lang.String   getSimpleTestAddress();  
   
          public   test.generated.SimpleTest   getSimpleTest()   throws   javax.xml.rpc.ServiceException;  
   
          public   test.generated.SimpleTest   getSimpleTest(java.net.URL   portAddress)   throws   javax.xml.rpc.ServiceException;  
  }  
  SimpleTestServiceLocator.java  
  .......  
   
  SimpleTestSoapBindingStub  
  .............  
  然后我建了一个class,按照你那样的写就有问题,请多多指教啊  
   
   
   
  Top

14 楼zcjl()回复于 2005-04-02 13:15:52 得分 0

然后我建了一个class,按照你那样的写就有问题,请多多指教啊  
   
   
  >>>>  
  关键是这个类的内容,还有错误信息  
  你不提供给我,我也不知道哪里有问题啊Top

15 楼freesnower1001(云淡风轻)回复于 2005-04-02 13:38:16 得分 0

SimpleTestServiceLocator.java  
   
  public   class   SimpleTestServiceLocator   extends   org.apache.axis.client.Service   implements   test.generated.SimpleTestService   {  
   
          //   Use   to   get   a   proxy   class   for   SimpleTest  
          private   java.lang.String   SimpleTest_address   =   "http://localhost:8080/t/services/SimpleTest";  
   
          public   java.lang.String   getSimpleTestAddress()   {  
                  return   SimpleTest_address;  
          }  
   
          //   The   WSDD   service   name   defaults   to   the   port   name.  
          private   java.lang.String   SimpleTestWSDDServiceName   =   "SimpleTest";  
   
          public   java.lang.String   getSimpleTestWSDDServiceName()   {  
                  return   SimpleTestWSDDServiceName;  
          }  
   
          public   void   setSimpleTestWSDDServiceName(java.lang.String   name)   {  
                  SimpleTestWSDDServiceName   =   name;  
          }  
   
          public   test.generated.SimpleTest   getSimpleTest()   throws   javax.xml.rpc.ServiceException   {  
                java.net.URL   endpoint;  
                  try   {  
                          endpoint   =   new   java.net.URL(SimpleTest_address);  
                  }  
                  catch   (java.net.MalformedURLException   e)   {  
                          throw   new   javax.xml.rpc.ServiceException(e);  
                  }  
                  return   getSimpleTest(endpoint);  
          }  
   
          public   test.generated.SimpleTest   getSimpleTest(java.net.URL   portAddress)   throws   javax.xml.rpc.ServiceException   {  
                  try   {  
                          test.generated.SimpleTestSoapBindingStub   _stub   =   new   test.generated.SimpleTestSoapBindingStub(portAddress,   this);  
                          _stub.setPortName(getSimpleTestWSDDServiceName());  
                          return   _stub;  
                  }  
                  catch   (org.apache.axis.AxisFault   e)   {  
                          return   null;  
                  }  
          }  
   
          public   void   setSimpleTestEndpointAddress(java.lang.String   address)   {  
                  SimpleTest_address   =   address;  
          }  
   
          /**  
            *   For   the   given   interface,   get   the   stub   implementation.  
            *   If   this   service   has   no   port   for   the   given   interface,  
            *   then   ServiceException   is   thrown.  
            */  
          public   java.rmi.Remote   getPort(Class   serviceEndpointInterface)   throws   javax.xml.rpc.ServiceException   {  
                  try   {  
                          if   (test.generated.SimpleTest.class.isAssignableFrom(serviceEndpointInterface))   {  
                                  test.generated.SimpleTestSoapBindingStub   _stub   =   new   test.generated.SimpleTestSoapBindingStub(new   java.net.URL(SimpleTest_address),   this);  
                                  _stub.setPortName(getSimpleTestWSDDServiceName());  
                                  return   _stub;  
                          }  
                  }  
                  catch   (java.lang.Throwable   t)   {  
                          throw   new   javax.xml.rpc.ServiceException(t);  
                  }  
                  throw   new   javax.xml.rpc.ServiceException("There   is   no   stub   implementation   for   the   interface:     "   +   (serviceEndpointInterface   ==   null   ?   "null"   :   serviceEndpointInterface.getName()));  
          }  
   
          /**  
            *   For   the   given   interface,   get   the   stub   implementation.  
            *   If   this   service   has   no   port   for   the   given   interface,  
            *   then   ServiceException   is   thrown.  
            */  
          public   java.rmi.Remote   getPort(javax.xml.namespace.QName   portName,   Class   serviceEndpointInterface)   throws   javax.xml.rpc.ServiceException   {  
                  if   (portName   ==   null)   {  
                          return   getPort(serviceEndpointInterface);  
                  }  
                  java.lang.String   inputPortName   =   portName.getLocalPart();  
                  if   ("SimpleTest".equals(inputPortName))   {  
                          return   getSimpleTest();  
                  }  
                  else     {  
                          java.rmi.Remote   _stub   =   getPort(serviceEndpointInterface);  
                          ((org.apache.axis.client.Stub)   _stub).setPortName(portName);  
                          return   _stub;  
                  }  
          }  
   
          public   javax.xml.namespace.QName   getServiceName()   {  
                  return   new   javax.xml.namespace.QName("http://test",   "SimpleTestService");  
          }  
   
          private   java.util.HashSet   ports   =   null;  
   
          public   java.util.Iterator   getPorts()   {  
                  if   (ports   ==   null)   {  
                          ports   =   new   java.util.HashSet();  
                          ports.add(new   javax.xml.namespace.QName("http://test",   "SimpleTest"));  
                  }  
                  return   ports.iterator();  
          }  
   
          /**  
          *   Set   the   endpoint   address   for   the   specified   port   name.  
          */  
          public   void   setEndpointAddress(java.lang.String   portName,   java.lang.String   address)   throws   javax.xml.rpc.ServiceException   {  
                  if   ("SimpleTest".equals(portName))   {  
                          setSimpleTestEndpointAddress(address);  
                  }  
                  else   {   //   Unknown   Port   Name  
                          throw   new   javax.xml.rpc.ServiceException("   Cannot   set   Endpoint   Address   for   Unknown   Port"   +   portName);  
                  }  
          }  
   
   
   
  Top

16 楼freesnower1001(云淡风轻)回复于 2005-04-02 13:40:09 得分 0

SimpleTestSoapBindingStub.java  
  public   class   SimpleTestSoapBindingStub   extends   org.apache.axis.client.Stub   implements   test.generated.SimpleTest   {  
          private   java.util.Vector   cachedSerClasses   =   new   java.util.Vector();  
          private   java.util.Vector   cachedSerQNames   =   new   java.util.Vector();  
          private   java.util.Vector   cachedSerFactories   =   new   java.util.Vector();  
          private   java.util.Vector   cachedDeserFactories   =   new   java.util.Vector();  
   
          static   org.apache.axis.description.OperationDesc   []   _operations;  
   
          static   {  
                  _operations   =   new   org.apache.axis.description.OperationDesc[1];  
                  _initOperationDesc1();  
          }  
   
          private   static   void   _initOperationDesc1(){  
                  org.apache.axis.description.OperationDesc   oper;  
                  oper   =   new   org.apache.axis.description.OperationDesc();  
                  oper.setName("process");  
                  oper.addParameter(new   javax.xml.namespace.QName("",   "in0"),   new   javax.xml.namespace.QName("http://test",   "Message"),   test.generated.Message.class,   org.apache.axis.description.ParameterDesc.IN,   false,   false);  
                  oper.setReturnType(new   javax.xml.namespace.QName("http://test",   "Message"));  
                  oper.setReturnClass(test.generated.Message.class);  
                  oper.setReturnQName(new   javax.xml.namespace.QName("",   "processReturn"));  
                  oper.setStyle(org.apache.axis.enum.Style.RPC);  
                  oper.setUse(org.apache.axis.enum.Use.ENCODED);  
                  _operations[0]   =   oper;  
   
          }  
   
          public   SimpleTestSoapBindingStub()   throws   org.apache.axis.AxisFault   {  
                    this(null);  
          }  
   
          public   SimpleTestSoapBindingStub(java.net.URL   endpointURL,   javax.xml.rpc.Service   service)   throws   org.apache.axis.AxisFault   {  
                    this(service);  
                    super.cachedEndpoint   =   endpointURL;  
          }  
   
          public   SimpleTestSoapBindingStub(javax.xml.rpc.Service   service)   throws   org.apache.axis.AxisFault   {  
                  if   (service   ==   null)   {  
                          super.service   =   new   org.apache.axis.client.Service();  
                  }   else   {  
                          super.service   =   service;  
                  }  
                          java.lang.Class   cls;  
                          javax.xml.namespace.QName   qName;  
                          java.lang.Class   beansf   =   org.apache.axis.encoding.ser.BeanSerializerFactory.class;  
                          java.lang.Class   beandf   =   org.apache.axis.encoding.ser.BeanDeserializerFactory.class;  
                          java.lang.Class   enumsf   =   org.apache.axis.encoding.ser.EnumSerializerFactory.class;  
                          java.lang.Class   enumdf   =   org.apache.axis.encoding.ser.EnumDeserializerFactory.class;  
                          java.lang.Class   arraysf   =   org.apache.axis.encoding.ser.ArraySerializerFactory.class;  
                          java.lang.Class   arraydf   =   org.apache.axis.encoding.ser.ArrayDeserializerFactory.class;  
                          java.lang.Class   simplesf   =   org.apache.axis.encoding.ser.SimpleSerializerFactory.class;  
                          java.lang.Class   simpledf   =   org.apache.axis.encoding.ser.SimpleDeserializerFactory.class;  
                          java.lang.Class   simplelistsf   =   org.apache.axis.encoding.ser.SimpleListSerializerFactory.class;  
                          java.lang.Class   simplelistdf   =   org.apache.axis.encoding.ser.SimpleListDeserializerFactory.class;  
                          qName   =   new   javax.xml.namespace.QName("http://test",   "Message");  
                          cachedSerQNames.add(qName);  
                          cls   =   test.generated.Message.class;  
                          cachedSerClasses.add(cls);  
                          cachedSerFactories.add(beansf);  
                          cachedDeserFactories.add(beandf);  
   
                          qName   =   new   javax.xml.namespace.QName("http://test",   "Property");  
                          cachedSerQNames.add(qName);  
                          cls   =   test.generated.Property.class;  
                          cachedSerClasses.add(cls);  
                          cachedSerFactories.add(beansf);  
                          cachedDeserFactories.add(beandf);  
   
                          qName   =   new   javax.xml.namespace.QName("http://test",   "ArrayOfProperty");  
                          cachedSerQNames.add(qName);  
                          cls   =   test.generated.Property[].class;  
                          cachedSerClasses.add(cls);  
                          cachedSerFactories.add(arraysf);  
                          cachedDeserFactories.add(arraydf);  
   
          }  
   
          private   org.apache.axis.client.Call   createCall()   throws   java.rmi.RemoteException   {  
                  try   {  
                          org.apache.axis.client.Call   _call   =  
                                          (org.apache.axis.client.Call)   super.service.createCall();  
                          if   (super.maintainSessionSet)   {  
                                  _call.setMaintainSession(super.maintainSession);  
                          }  
                          if   (super.cachedUsername   !=   null)   {  
                                  _call.setUsername(super.cachedUsername);  
                          }  
                          if   (super.cachedPassword   !=   null)   {  
                                  _call.setPassword(super.cachedPassword);  
                          }  
                          if   (super.cachedEndpoint   !=   null)   {  
                                  _call.setTargetEndpointAddress(super.cachedEndpoint);  
                          }  
                          if   (super.cachedTimeout   !=   null)   {  
                                  _call.setTimeout(super.cachedTimeout);  
                          }  
                          if   (super.cachedPortName   !=   null)   {  
                                  _call.setPortName(super.cachedPortName);  
                          }  
                          java.util.Enumeration   keys   =   super.cachedProperties.keys();  
                          while   (keys.hasMoreElements())   {  
                                  java.lang.String   key   =   (java.lang.String)   keys.nextElement();  
                                  _call.setProperty(key,   super.cachedProperties.get(key));  
                          }  
  待续Top

17 楼freesnower1001(云淡风轻)回复于 2005-04-02 13:40:28 得分 0

//   All   the   type   mapping   information   is   registered  
                          //   when   the   first   call   is   made.  
                          //   The   type   mapping   information   is   actually   registered   in  
                          //   the   TypeMappingRegistry   of   the   service,   which  
                          //   is   the   reason   why   registration   is   only   needed   for   the   first   call.  
                          synchronized   (this)   {  
                                  if   (firstCall())   {  
                                          //   must   set   encoding   style   before   registering   serializers  
                                          _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);  
                                          _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);  
                                          for   (int   i   =   0;   i   <   cachedSerFactories.size();   ++i)   {  
                                                  java.lang.Class   cls   =   (java.lang.Class)   cachedSerClasses.get(i);  
                                                  javax.xml.namespace.QName   qName   =  
                                                                  (javax.xml.namespace.QName)   cachedSerQNames.get(i);  
                                                  java.lang.Class   sf   =   (java.lang.Class)  
                                                                    cachedSerFactories.get(i);  
                                                  java.lang.Class   df   =   (java.lang.Class)  
                                                                    cachedDeserFactories.get(i);  
                                                  _call.registerTypeMapping(cls,   qName,   sf,   df,   false);  
                                          }  
                                  }  
                          }  
                          return   _call;  
                  }  
                  catch   (java.lang.Throwable   _t)   {  
                          throw   new   org.apache.axis.AxisFault("Failure   trying   to   get   the   Call   object",   _t);  
                  }  
          }  
   
          public   test.generated.Message   process(test.generated.Message   in0)   throws   java.rmi.RemoteException   {  
                  if   (super.cachedEndpoint   ==   null)   {  
                          throw   new   org.apache.axis.NoEndPointException();  
                  }  
                  org.apache.axis.client.Call   _call   =   createCall();  
                  _call.setOperation(_operations[0]);  
                  _call.setUseSOAPAction(true);  
                  _call.setSOAPActionURI("");  
                  _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);  
                  _call.setOperationName(new   javax.xml.namespace.QName("http://test",   "process"));  
   
                  setRequestHeaders(_call);  
                  setAttachments(_call);  
                  java.lang.Object   _resp   =   _call.invoke(new   java.lang.Object[]   {in0});  
   
                  if   (_resp   instanceof   java.rmi.RemoteException)   {  
                          throw   (java.rmi.RemoteException)_resp;  
                  }  
                  else   {  
                          extractAttachments(_call);  
                          try   {  
                                  return   (test.generated.Message)   _resp;  
                          }   catch   (java.lang.Exception   _exception)   {  
                                  return   (test.generated.Message)   org.apache.axis.utils.JavaUtils.convert(_resp,   test.generated.Message.class);  
                          }  
                  }  
          }  
   
  }  
  Top

18 楼zcjl()回复于 2005-04-02 13:44:03 得分 0

晕啊,我是要你那个出错的测试程序代码,还有异常信息Top

19 楼freesnower1001(云淡风轻)回复于 2005-04-02 13:44:07 得分 0

我发布的service和相关类如下:  
  发布的类及其方法:  
  public   class   SimpleTest   {  
          public   SimpleTest()   {  
          }  
           
          public   Message   process(Message   in0){  
                  Message   m=new   Message();  
                  Property   a=new   Property();  
                  a.key="afe";  
                  a.value="dd";  
                  m.properties[0]=a;  
                   
                  return   m;  
          }  
  }  
  相关的类:  
   
  public   class   Message   {  
          public   Property[]   properties;  
          public   Message()   {  
          }  
  }  
  public   class   Property   {  
          public   String   key;  
          public   String   value;  
          public   Property()   {  
          }  
  }  
  Top

20 楼freesnower1001(云淡风轻)回复于 2005-04-02 14:06:27 得分 0

我写的调用的类如下:  
  public   class   testjavaweb   {  
          public   static   void   main(String[]   args)   throws   ServiceException   {  
   
                  SimpleTestServiceLocator   loc   =   new   SimpleTestServiceLocator();  
                  SimpleTest   cs   =   loc.getSimpleTest();  
   
                  Message   g   =   new   Message();  
                  Message   r   =   new   Message();  
   
                  Property   k   =   new   Property();  
                  k.key   =   "afe";  
                  k.value   =   "dd";  
                  g.properties   =   new   Property[]   {k};  
                    r=cs.process(g);   //就是这里有错,"testjavaweb.java":   process(test.generated.Message)   in   test.generated.SimpleTest   cannot   be   applied   to   (test.Message)   at   line   33,   column   15  
   
                  System.out.println(r.properties.length);  
          }  
   
          public   testjavaweb()   {  
          }  
  }Top

21 楼zcjl()回复于 2005-04-02 14:35:46 得分 0

涉及自定义类型?  
   
  r=cs.process(g);    
  这里的参数g的类型应该是生成的test.generated.Message,而不是在服务端定义的test.MessageTop

22 楼freesnower1001(云淡风轻)回复于 2005-04-02 14:50:10 得分 0

是啊:(  
   
  可我还是不知道要怎么写?请指教Top

23 楼yangxinfengg(丰丰)回复于 2005-04-08 15:32:59 得分 0

通过wsdl在客户端生成的类是不是与所用的服务器有关啊   ?好像服务器不同所生成的代理类也又不同啊。Top

相关问题

  • .net调用java写的webservice
  • 怎样调用java写的WebService啊
  • java调用delphi的webservice问题?
  • php如何调用java写的webservice?
  • VB调用JAVA的WEBSERVICE返回XML结构集 的问题急急啊,求救!!!
  • VB调用JAVA的WEBSERVICE返回XML结构集 的问题急急啊,求救!!!
  • VB调用WebService?
  • vc.net调用webservice
  • JAVA调用DB2失败(急~~~~)!!!
  • Axis下WebService的调用问题,急!!!

关键词

  • .net
  • service
  • cityservice
  • 调用
  • servicefactory
  • qname
  • servicename
  • 例子
  • city
  • 请大家给出一个

得分解答快速导航

  • 帖主:freesnower1001
  • zcjl
  • joybo

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo