我正在创建一个JAX-RPC Web服务客户端,但是当我调用webservice时,它给了我错误:
org.apache.naming.ServiceRef无法强制转换为javax.xml.rpc.Service
客户代码
Context ctx= new InitialContext();
Service service = (Service)ctx.lookup("java:comp/env/service/ROServiceImplService");
QName portQName= new QName("http://services.nic.in","ROServiceImpl");
ROServiceImpl svc = (ROServiceImpl) service.getPort(portQName,ROServiceImpl.class);
String roCode=svc.getROCode(scForm.getEmpCode(),"ashish","6295");
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>
serviceclient</display-name>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>validate</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<service-ref>
<description>WSDL Service ROServiceImplService</description>
<service-ref-name>service/ROServiceImplService</service-ref-name>
<service-interface>javax.xml.rpc.Service</service-interface>
<wsdl-file>WEB-INF/wsdl/ROServiceImpl.wsdl</wsdl-file>
</service-ref>
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-template.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
ROServiceImpl Code
package in.nic.services;
public interface ROServiceImpl extends java.rmi.Remote {
public java.lang.String getROCode(java.lang.String empCode, java.lang.String uname, java.lang.String pwd) throws java.rmi.RemoteException;
}
ROServiceImpl.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://services.nic.in" xmlns:impl="http://services.nic.in" xmlns:intf="http://services.nic.in" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsi="http://ws-i.org/profiles/basic/1.1/xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema targetNamespace="http://services.nic.in" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:impl="http://services.nic.in" xmlns:intf="http://services.nic.in" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<element name="getROCodeResponse">
<complexType>
<sequence>
<element name="getROCodeReturn" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="getROCode">
<complexType>
<sequence>
<element name="empCode" nillable="true" type="xsd:string"/>
<element name="uname" nillable="true" type="xsd:string"/>
<element name="pwd" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="getROCodeResponse">
<wsdl:part element="impl:getROCodeResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getROCodeRequest">
<wsdl:part element="impl:getROCode" name="parameters"/>
</wsdl:message>
<wsdl:portType name="ROServiceImpl">
<wsdl:operation name="getROCode">
<wsdl:input message="impl:getROCodeRequest" name="getROCodeRequest"/>
<wsdl:output message="impl:getROCodeResponse" name="getROCodeResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ROServiceImplSoapBinding" type="impl:ROServiceImpl">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getROCode">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getROCodeRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getROCodeResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ROServiceImplService">
<wsdl:port binding="impl:ROServiceImplSoapBinding" name="ROServiceImpl">
<wsdlsoap:address location="http://localhost:9080/ehradmwebservice/services/ROServiceImpl"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>