Java JAX-WSWeb服务:从控制台应用程序切换到web应用程序

Java JAX-WSWeb服务:从控制台应用程序切换到web应用程序,java,eclipse,soap,web,war,Java,Eclipse,Soap,Web,War,我在Eclipse的控制台应用程序中创建了以下三个类: @WebService(endpointInterface = "uk.co.hello.Details") public class DetailsImpl implements Details{ public String getDetails() { return "Hello"; } } @WebService @SOAPBinding(style = Style.RPC) public inte

我在Eclipse的控制台应用程序中创建了以下三个类:

@WebService(endpointInterface = "uk.co.hello.Details")
public class DetailsImpl implements Details{
    public String getDetails() {

        return "Hello";
    }
}

@WebService
@SOAPBinding(style = Style.RPC)
public interface Details{

    @WebMethod String getDetails();
}

public class DetailsPublisher{

    public static void main(String[] args) {
       Endpoint endpoint = Endpoint.publish("http://localhost:9900/mytest", new DetailsImpl());
       System.out.println(endpoint.isPublished());
    }
}
一切都很好,我可以发布我的web服务并使用它


现在我创建了一个web应用程序,我想在JBoss上部署我的东西。也许我不再需要main方法,而是需要其他方法。有人能给我举个例子,说明为了生成一个有效的war,我需要更改什么吗?

您可以将您的
EJB
发布为
SOAP
服务,但我从未听说有人在war中在web层发布SOAP服务

为了使其与支持EJB 3.0的JBoss一起工作: a) 指定EJB接口。

import java.rmi.Remote;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style = Style.RPC)
public interface SOAPService extends Remote {
        String service();
}
b) 指定EJB:

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.jws.WebService;

@Stateless
@WebService(endpointInterface = "full.package.and.name.of.SOAPService")
@Remote(SOAPService.class)
public class EchoBean {
        public String service() {
                return "SOAP Serviced";
        }
}
c) 在JBoss上作为EJB jar部署。

import java.rmi.Remote;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style = Style.RPC)
public interface SOAPService extends Remote {
        String service();
}

d) 测试

如果您了解spring,您可以使用cxf框架,使用eclipse可以找到一个很好的教程。您可以使用自下而上的方法