日期:2014-05-20  浏览次数:20754 次

如何把一个ejb3项目在Jboss5.1上发布成拥有一套接口的WebService?
我现在做了一个ejb3的小例子,里面分别有一个remote的sessionBean(HelloWorld)和local的sessionBean(GoodByeWorld),并成功发布到Jboss5上面,调用也没问题.
因为想用根据ejb3项目发布成WebService,所以按照网上的例子我加上了WebService之类的标签,当然发布也成功了,调用也没问题,但却分别得到两个不同的wsdl地址.然而事实上我想要的是拥有这两个接口例子的一个wsdl,即想相对应整个项目而不是一个地址对应一个接口,请问怎么做?


为了让大家能够更加的了解问题所在,就顺便贴出代码出来:
(我用的是eclipse3.7 + Jboss 5.1 + ejb3.0)
HelloWorldRemote接口
Java code

package com.allen;
import javax.ejb.Remote;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@Remote
@WebService(name = "HelloWorldRemote")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface HelloWorldRemote {
   String sayHello(String name);
}



HelloWorld实现类
Java code

package com.allen;

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

import org.jboss.wsf.spi.annotation.WebContext;

/**
 * Session Bean implementation class HelloWorld
 */
@Stateless
@Remote(HelloWorldRemote.class)
@WebService(endpointInterface ="com.allen.HelloWorldRemote",serviceName ="MyWorld")
@WebContext(contextRoot="")
public class HelloWorld implements HelloWorldRemote {

    @WebMethod
    public String sayHello(String name) {
        // TODO Auto-generated method stub
        return "Hello!"+name;
    }

}



GoodByeWorld接口
Java code

package com.allen;
import javax.ejb.Local;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@Local
@WebService(name = "GoodByeWorldLocal")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface GoodByeWorldLocal {
   String sayGoodBye(String name);
}




GoodByeWorld实现类
Java code

package com.allen;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.jws.WebService;

/**
 * Session Bean implementation class GoodByeWorld
 */
@Stateless
@Local(GoodByeWorldLocal.class)
@WebService(endpointInterface ="com.allen.GoodByeWorldLocal",serviceName ="MyWorld")
public class GoodByeWorld implements GoodByeWorldLocal {

    /* (non-Javadoc)
     * @see com.allen.GoodByeWorldLocal#sayGoodBye(java.lang.String)
     */
    public String sayGoodBye(String name) {
        // TODO Auto-generated method stub
        return "GoodBye!Dear "+ name;
    }

}





------解决方案--------------------
接口:
Java code

package com.huawei.datavoice.measurement.service;
import javax.ejb.Remote;

@Remote
public interface MeasurementService {
    
    void recalculate(int indexInstanceId) throws Exception;

}