采用CXF发布web service
服务器端接口
/**
 * 获取ucpi数据库中收录的子库的信息
 * @author Administrator
 *
 */
@WebService
public interface InfoWS {
public List<String> getDbNameList(); public String getDbMetaInfo(String dbName);
实现类
@WebService(endpointInterface="org.hlpp.ucpi.webservice.InfoWS", serviceName = "infoWS")
public class InfoWSImpl {
private MetaInfoService metaInfoService; public MetaInfoService getMetaInfoService() {
return metaInfoService;
} public void setMetaInfoService(MetaInfoService metaInfoService) {
this.metaInfoService = metaInfoService;
} public String getDbMetaInfo(String dbName) { return metaInfoService.getDbMetaInfo(dbName).getDbname();
} public List<String> getDbNameList() {
return metaInfoService.getDbNameList();
}}
spring的配置文件<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<jaxws:endpoint id="infoWS" implementor="#infoBean" address="/infoWS" />
<bean id="infoBean" class="org.hlpp.ucpi.webservice.impl.InfoWSImpl">
<property name="metaInfoService">
<ref bean="metaInfoService"/>
</property>
</bean>启动tomcat发布后,可以从浏览器看到wsdl文件http://localhost:8080/ucpi/webservice/infoWS?wsdl
奇怪的是wsdl文件特别短,好像不太正常
写了个客户端测试也出错

client.java的代码
public static void main(String[] args) throws IOException {
// TODO 自动生成方法存根
ClientProxyFactoryBean factory = new ClientProxyFactoryBean();

/************InfoWS的测试*****************/
factory.setServiceClass(InfoWS.class);
factory.setAddress("http://localhost:8080/ucpi/webservice/infoWS");
InfoWS infows = (InfoWS)factory.create();
//InfoWS的getDbNameList方法
List<String> list = infows.getDbNameList();
for(String s:list)System.out.println("数据库名:"+s);
//InfoWS的getDbMetaInfo方法
String dbinfo = infows.getDbMetaInfo("dbLEP");
System.out.println("数据库名:"+dbinfo);
出错信息:
Exception in thread "main" java.lang.NullPointerException
at test.Client.main(Client.java:37)

infows这个对象根本没得到
检查了半天也不知道哪出错了

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【yutianl】截止到2008-06-25 13:54:19的历史汇总数据(不包括此帖):
    发帖数:9                  发帖分:190                
    结贴数:3                  结贴分:70                 
    未结数:6                  未结分:120                
    结贴率:33.33 %            结分率:36.84 %            
    楼主该结一些帖子了
      

  2.   

    wsdl文件内容
    <?xml version="1.0" encoding="UTF-8" ?> 
    - <wsdl:definitions name="infoWS" targetNamespace="http://impl.webservice.ucpi.hlpp.org/" xmlns:ns1="http://webservice.ucpi.hlpp.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://impl.webservice.ucpi.hlpp.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <wsdl:import location="http://localhost:8080/ucpi/webservice/infoWS?wsdl=InfoWS.wsdl" namespace="http://webservice.ucpi.hlpp.org/" /> 
    - <wsdl:binding name="infoWSSoapBinding" type="ns1:InfoWS">
      <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> 
    - <wsdl:operation name="getDbMetaInfo">
      <soap:operation soapAction="" style="document" /> 
    - <wsdl:input name="getDbMetaInfo">
      <soap:body use="literal" /> 
      </wsdl:input>
    - <wsdl:output name="getDbMetaInfoResponse">
      <soap:body use="literal" /> 
      </wsdl:output>
      </wsdl:operation>
    - <wsdl:operation name="getDbNameList">
      <soap:operation soapAction="" style="document" /> 
    - <wsdl:input name="getDbNameList">
      <soap:body use="literal" /> 
      </wsdl:input>
    - <wsdl:output name="getDbNameListResponse">
      <soap:body use="literal" /> 
      </wsdl:output>
      </wsdl:operation>
      </wsdl:binding>
    - <wsdl:service name="infoWS">
    - <wsdl:port binding="tns:infoWSSoapBinding" name="InfoWSImplPort">
      <soap:address location="http://localhost:8080/ucpi/webservice/infoWS" /> 
      </wsdl:port>
      </wsdl:service>
      </wsdl:definitions>