webservice客户端出错java.lang.IllegalStateException:Service class is not an interface

happy_lin 2010-11-16 11:51:28
我通过wsdl生成客户端代码,然后在eclipse运行成功人,但是单独部署,通过运行脚本调用,不依赖eclipse就报
java.lang.IllegalStateException: Service class is not an interface. Please use an interface specify or specify one via a @WebService annotation.
at org.codehaus.xfire.client.XFireProxyFactory.create(XFireProxyFactory.java:109)
at org.codehaus.xfire.client.XFireProxyFactory.create(XFireProxyFactory.java:146)
经查代码发现create出错:
private static XFireProxyFactory proxyFactory = new XFireProxyFactory();
proxyFactory.create((endpoint).getBinding(), (endpoint).getUrl());
请问是什么原因啊?

...全文
1420 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
happy_lin 2011-05-31
  • 打赏
  • 举报
回复
是因为相同的类在jar包里也有,估计是部署后先引用jar包中的方法,由于jar包里的方法是错误的,没有用java类因此出错了。
_豆包儿_ 2011-05-06
  • 打赏
  • 举报
回复
咋解决的啊?LZ分享一下呗!!!
happy_lin 2010-12-07
  • 打赏
  • 举报
回复
找到原因了,高兴!!!!!!!
happy_lin 2010-11-24
  • 打赏
  • 举报
回复
自己顶下!!!!!!!!!!!!!!!
happy_lin 2010-11-22
  • 打赏
  • 举报
回复
下面我把代码贴出来,各位帮我看下,在eclipse下面跑正常,但是单独部署就出错,经调试是
System.out.println("(endpoint).getUrl()"+(endpoint).getUrl());
System.out.println("(endpoint).getBinding()"+(endpoint).getBinding());
System.out.println("==========two"+proxyFactory.create((endpoint).getBinding(), (endpoint).getUrl()));

最后一个sysout没有输出,但是我看了下create里面两个参数都是接口对像啊!高手帮忙看下,万分感谢!!

原码为:
package com.cmbc.migration.report;

import java.net.MalformedURLException;
import java.util.Collection;
import java.util.HashMap;
import javax.xml.namespace.QName;
import org.codehaus.xfire.aegis.AegisBindingProvider;
import org.codehaus.xfire.annotations.AnnotationServiceFactory;
import org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.jaxb2.JaxbTypeRegistry;
import org.codehaus.xfire.service.Endpoint;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.soap.AbstractSoapBinding;
import org.codehaus.xfire.transport.TransportManager;

public class Model3ReportServiceClient {

private static XFireProxyFactory proxyFactory = new XFireProxyFactory();
private HashMap endpoints = new HashMap();
private Service service0;

public Model3ReportServiceClient() {
System.out.println("Model3ReportServiceClient Start!!!!!!!!!!!");
create0();
Endpoint Model3ReportPortEP = service0 .addEndpoint(new QName("http://com/cmbc/migration/report", "Model3ReportPort"), new QName("http://com/cmbc/migration/report", "Model3ReportServiceHttpBinding"), "http://197.3.7.105:8080/MigrationPlatform/services/Model3ReportService");
endpoints.put(new QName("http://com/cmbc/migration/report", "Model3ReportPort"), Model3ReportPortEP);
Endpoint Model3ReportLocalEndpointEP = service0 .addEndpoint(new QName("http://com/cmbc/migration/report", "Model3ReportLocalEndpoint"), new QName("http://com/cmbc/migration/report", "Model3ReportLocalBinding"), "xfire.local://Model3ReportService");
System.out.println("Model3ReportLocalEndpointEP"+Model3ReportLocalEndpointEP);
endpoints.put(new QName("http://com/cmbc/migration/report", "Model3ReportLocalEndpoint"), Model3ReportLocalEndpointEP);
}

public Object getEndpoint(Endpoint endpoint) throws Exception{
System.out.println("getEndpoint!!!!!!!!!!");
try {
System.out.println("(endpoint).getUrl()"+(endpoint).getUrl());
System.out.println("(endpoint).getBinding()"+(endpoint).getBinding());
System.out.println("==========two"+proxyFactory.create((endpoint).getBinding(), (endpoint).getUrl()));
return proxyFactory.create((endpoint).getBinding(), (endpoint).getUrl());
} catch (MalformedURLException e) {
System.out.println("getEndpoint"+e.getMessage());
throw new Exception("Invalid URL", e);
}
}

public Object getEndpoint(QName name) throws Exception{
System.out.println("getEndpoint()!!!!!!!!!!");
Endpoint endpoint = ((Endpoint) endpoints.get((name)));
System.out.println("getEndpoint name"+endpoint);
if ((endpoint) == null) {
throw new IllegalStateException("No such endpoint!");
}
return getEndpoint((endpoint));
}

public Collection getEndpoints() {
return endpoints.values();
}

private void create0() {
System.out.println("create0!!!!!!!!!!");
TransportManager tm = (org.codehaus.xfire.XFireFactory.newInstance().getXFire().getTransportManager());
HashMap props = new HashMap();
props.put("annotations.allow.interface", true);
AnnotationServiceFactory asf = new AnnotationServiceFactory(new Jsr181WebAnnotations(), tm, new AegisBindingProvider(new JaxbTypeRegistry()));
asf.setBindingCreationEnabled(false);
service0 = asf.create((com.cmbc.migration.report.Model3Report.class), props);
{
AbstractSoapBinding soapBinding = asf.createSoap11Binding(service0, new QName("http://com/cmbc/migration/report", "Model3ReportLocalBinding"), "urn:xfire:transport:local");
}
{
AbstractSoapBinding soapBinding = asf.createSoap11Binding(service0, new QName("http://com/cmbc/migration/report", "Model3ReportServiceHttpBinding"), "http://schemas.xmlsoap.org/soap/http");
}

}

public Model3Report getModel3ReportPort() throws Exception{
System.out.println("getModel3ReportPort!!!!!!!!!!");
return ((Model3Report)(this).getEndpoint(new QName("http://com/cmbc/migration/report", "Model3ReportPort")));
}

public Model3Report getModel3ReportPort(String url) {
System.out.println("getModel3ReportPort(url)!!!!!!!!!!");
Model3Report var=null;
try{
var = getModel3ReportPort();
org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);
}catch(Exception e){
System.out.println(e.getMessage());
}
return var;
}

public Model3Report getModel3ReportLocalEndpoint() throws Exception{
return ((Model3Report)(this).getEndpoint(new QName("http://com/cmbc/migration/report", "Model3ReportLocalEndpoint")));
}

public Model3Report getModel3ReportLocalEndpoint(String url) {
Model3Report var=null;
try{
var = getModel3ReportLocalEndpoint();
org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);
}catch(Exception e){
System.out.println(e.getMessage());
}
return var;
}
jiazimo 2010-11-22
  • 打赏
  • 举报
回复
楼上的调用正解。
是不是你调用的接口不对?
接口 clients = (接口) proxy.create(service,url);//是接口,而不是实现
madFatso 2010-11-22
  • 打赏
  • 举报
回复
把服务端WEBSETVICE接口加入到客户端
Service service = new ObjectServiceFactory().create(接口.class);
XFire xfire = XFireFactory.newInstance().getXFire();
XFireProxyFactory proxy = new XFireProxyFactory(xfire);

接口 clients = (接口) proxy.create(service,url);
加贝氏_usun 2010-11-22
  • 打赏
  • 举报
回复
没用过xfire,配置时候,有一个接口,然后一个实现类。
你这个错误很明显 就是在要接口的地方,你用的不是接口。
检查核实一先,有问题再讨论
lk198186 2010-11-22
  • 打赏
  • 举报
回复
没用过xfire,从异常看是非法状态异常,你调用的类不是一个接口
happy_lin 2010-11-17
  • 打赏
  • 举报
回复
难道没有懂吗???
happy_lin 2010-11-16
  • 打赏
  • 举报
回复
自己顶下了
happy_lin 2010-11-16
  • 打赏
  • 举报
回复
没人回复呢,补充:所有eclipse上用到的包单独部署时都加了,为什么还报错呢?

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧