我正在使用 jboss 4.2 服务器在 Eclipse 上开发一个 Web 服务示例。我创建了一个服务实现类,如下所示:
import java.util.HashMap;
import java.util.Map;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public class CarWebServiceImpl {
private final Map<String, Integer> prices = new HashMap<String, Integer>();
public CarWebServiceImpl() {
prices.put("audi", Integer.valueOf(10000));
prices.put("bmw", Integer.valueOf(150000));
prices.put("fiat", Integer.valueOf(5000));
}
@WebMethod
public Response getCarPrice(String carId) {
int price = prices.get(carId);
Response resp = new Response();
resp.setPrice(price);
return resp;
}
}
Web 服务会自动部署到服务器中,我可以在以下位置看到我的服务
http://127.0.0.1:8080/jbossws/services/
我创建了另一个项目并使用 wsconsume 实用程序生成客户端类文件。然后我将服务类实例化如下:
public class Client {
public static void main(String[] args) {
CarWebServiceImplService service = new CarWebServiceImplService();
CarWebServiceImpl port = service.getCarWebServiceImplPort();
port.getCarPrice("audi");
}
}
但是当我尝试运行客户端代码时,出现以下错误
Exception in thread "main" javax.xml.ws.WebServiceException: No Content-type in the header!
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:172)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:83)
at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:105)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:587)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:546)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:531)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:428)
at com.sun.xml.internal.ws.client.Stub.process(Stub.java:211)
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:124)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
at $Proxy25.getCarPrice(Unknown Source)
at wsclient.Client.main(Client.java:7)
我不知道我的方法有什么问题。请帮忙。提前致谢。