2013-02-13 70 views

回答

0

Apache AxisJAX-RPC是用於創建Web服務的獨立框架。沒有人能回答你的問題,因爲沒有正確的答案。我能做的只是給你一些啓動的鏈接,以便更好地理解JAX-RPC和Apache Axis。

參見:

從你以前所有與此相關的一個問題,我假設你需要支持rpc/encoded WSDL風格。那麼,JAX-RPC和Axis將會這樣做。不知道如何通過JAX-RPC做到這一點,但是這是一些提示如何與軸和Spring這樣做:

創建兩個類:

import org.apache.axis.EngineConfiguration; 
import org.apache.axis.Handler; 
import org.apache.axis.deployment.wsdd.WSDDProvider; 
import org.apache.axis.deployment.wsdd.WSDDService; 

public class WSDDSpringProvider extends WSDDProvider { 

    public static final String PROVIDER_NAME = "SPRING"; 
    public static final String PARAM_SPRING_BEAN_ID = "springBeanId"; 

    public String getName(){ 
     return "SPRING"; 
    } 

    public Handler newProviderInstance(WSDDService service, EngineConfiguration registry) 
     throws Exception { 
     return new SpringProvider(service.getParameter("springBeanId")); 
    } 

} 

而另:

import java.io.PrintStream; 
import java.lang.reflect.Method; 
import javax.servlet.Servlet; 
import javax.servlet.ServletConfig; 
import org.apache.axis.MessageContext; 
import org.apache.axis.providers.java.RPCProvider; 
import org.apache.axis.transport.http.HTTPConstants; 
import org.springframework.web.context.WebApplicationContext; 
import org.springframework.web.context.support.WebApplicationContextUtils; 

public class SpringProvider extends RPCProvider { 

    private String springBeanId; 

    public SpringProvider(String springBeanId) { 
     this.springBeanId = springBeanId; 
    } 

    protected Object makeNewServiceObject(MessageContext msgContext, String clsName) 
     throws Exception { 
     Servlet servlet = (Servlet)msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLET); 
     WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servlet.getServletConfig().getServletContext()); 
     return wac.getBean(springBeanId); 
    } 

    protected Object invokeMethod(MessageContext msgContext, Method method, Object obj, Object argValues[]) 
     throws Exception { 
     Method proxyMethod = obj.getClass().getMethod(method.getName(), method.getParameterTypes()); 
     return proxyMethod.invoke(obj, argValues); 
    } 

} 

製作他們作爲.jar文件並將其放入您的類路徑中。這些類是處理程序,您的Axis Web服務的實現類可以作爲Spring bean公開。

Axis WSDD文件配置java:SPRING您想公開爲Spring bean的Web服務的提供者。定義參數springBeanId的唯一值。例如(從WSDD文件):

<ns:service name="TestService" provider="java:SPRING" use="literal"> 
    <ns:parameter name="springBeanId" value="webServiceImpl" /> 
    <!-- ... --> 
</ns:service> 

定義Web服務實現如春豆在WEB-INF/applicationContext.xml,例如:

<bean id="webServiceImpl" class="your.pkg.WebServiceImpl"> 
</bean> 

這些步驟後,你就可以使用你的Web服務實現類普通 春豆。

+0

@ User222 JAX-WS已經取代了JAX-RPC。如果您正在實施,請考慮JAX-WS。另請閱讀:http://stackoverflow.com/questions/3307516/jax-ws-vs-jax-rpc/3314458#3314458 – user1428716 2013-02-13 20:28:38

相關問題