gpt4 book ai didi

java - 在 Eclipse 中创建一个简单的 JAX-WS WebService

转载 作者:搜寻专家 更新时间:2023-11-01 02:14:29 25 4
gpt4 key购买 nike

我正在尝试在 Eclipse 中创建一个简单的 Web 服务。首先我创建了一个空的 java 项目并在 src 文件夹中添加了以下三个文件

  1. 问候语.java
package com.alfaisaliah;

import javax.jws.WebService;
import javax.jws.WebMethod;

@WebService
public interface Greeting {
@WebMethod
String sayHello(String name);
}
  1. 问候语.java
package com.alfaisaliah;

import javax.jws.WebService;

@WebService(endpointInterface="com.alfaisaliah.Greeting")
public class GreetingImp implements Greeting {

@Override
public String sayHello(String name) {
return "Hello " + name;
}
}
  1. WSPublisher
package com.alfaisaliah;

import javax.xml.ws.Endpoint;

public class WSPublisher {
public static void main(String[] args){
Endpoint.publish("http://localhost:8081/WS/Greeting", new GreetingImp());
}
}

我正在学习的教程没有指定任何服务器来运行 Web 服务!我想知道是否需要指定任何服务器。我已经有 Tomcat v5.5,但我没有在这个例子中使用它。每当我将这个项目作为 java 项目运行时,我都会遇到某种错误。任何人都可以帮我确定我的问题是在哪里尝试运行网络服务。这是 eclipse 控制台的输出

Feb 26, 2012 12:01:00 PM com.sun.xml.internal.ws.model.RuntimeModeler getRequestWrapperClass
INFO: Dynamically creating request wrapper Class com.alfaisaliah.jaxws.SayHello

Feb 26, 2012 12:01:00 PM com.sun.xml.internal.ws.model.RuntimeModeler getResponseWrapperClass
INFO: Dynamically creating response wrapper bean Class com.alfaisaliah.jaxws.SayHelloResponse

另外,当我再次运行该项目时,它说该地址已被使用

Feb 26, 2012 12:01:00 PM com.sun.xml.internal.ws.model.RuntimeModeler getRequestWrapperClass
INFO: Dynamically creating request wrapper Class com.alfaisaliah.jaxws.SayHello

Feb 26, 2012 12:01:00 PM com.sun.xml.internal.ws.model.RuntimeModeler getResponseWrapperClass
INFO: Dynamically creating response wrapper bean Class com.alfaisaliah.jaxws.SayHelloResponse
Exception in thread "main" com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Address already in use

非常感谢你们的帮助:)

最佳答案

The tutorial i'm following doesn't specify any server to run the web service on! I'm wondering if I need to specify any server.

您不需要带有此代码的服务器。
你的主要在:

Endpoint.publish("http://localhost:8081/WS/Greeting", new GreetingImp());  

在引擎盖下启动一个轻型 http 服务器(在 JKD 1.6 之后可用)并部署您的 Web 服务来处理所有传入/传出流量。

这里的问题是你错过了一步:
您必须使用 wsgen 工具(在 java 中可用)生成所需的工件。

在这里查看:JAX WS tutorial对于
wsgen -d build -s build -classpath build
helloservice.endpoint.Hello

并阅读有关 wsgen 的内容。

老实说,我不记得你是如何通过 Eclipse 做到这一点的(实际上我不确定这是否可以在 Eclipse 中自动工作而不需要运行wsgen 自己),但您可以手动运行它并只需将生成的工件复制到您的项目中。

至于

Server Runtime Error: java.net.BindException: Address already in use

这是不言自明的:只需使用另一个端口。 8081 已被使用。

关于java - 在 Eclipse 中创建一个简单的 JAX-WS WebService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9451870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com