CXF和Spring中的SOAP客户端

时间:2015-08-10 11:39:49

标签: spring web-services cxf

我是Web Service和Apache CXF的新手。我创建了一个" Hello World" Web服务,现在尝试使用Simple Java Client。

为了用真实世界的例子来模拟它,我在Eclipse中创建了两个独立的项目(一个用于Server,一个用于Client)。

现在,我设法生成了我的WSDL。但我没有得到如何在不导入服务器存根的情况下从客户端请求此Web服务?因为,除了WSDL URL之外,我们在客户端没有任何可用的API。

我在很多网站上都经历了很多这样的例子。但他们正在导入端点接口但是如何?

我错过了什么吗?

提前致谢。

这是服务器端结构

界面 - CelciusFarenhite

实施 - CelciusFarenhiteImpl

这些类包含2个简单的转换方法。

的applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

    <bean id="tempCalcBean" class="com.aw.ws.impl.CelciusFarenhiteImpl" />

    <jaxws:endpoint id="temperatureService" implementor="#tempCalcBean" address="/tempCalc" />

</beans>   

Web.xml中

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    <display-name>AccuWeather</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>

客户端结构

的beans.xml

   <bean id="cricinfo" class="com.aw.ws.CelciusFarenhite" factory-bean="tempCalcBeanFactory" factory-method="create" />

   <bean id="tempCalcBeanFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
    <property name="serviceClass" value="com.aw.ws.CelciusFarenhite" />
    <property name="address" value="http://localhost:8080/AccuWeather/tempCalc" />
   </bean> 

测试类

package com.meteo.ws.client;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class TemperatureConverterClient extends TestCase
{
    ClassPathXmlApplicationContext appCtxt;

    @Override
    protected void setUp() throws Exception
    {
        appCtxt = new ClassPathXmlApplicationContext("beans.xml");

    }

    @Test
    public void testConvertTemperature()
    {
        appCtxt.start();
        Assert.assertNotNull(appCtxt);

        //How will it be imported??

        //CelciusFarenhite service = (CelciusFarenhite) applicationContext.getBean("cricinfo");

    }

}

现在,客户如何了解Server API(或CelciusFarenhite界面)?

0 个答案:

没有答案