`
erichua
  • 浏览: 510320 次
  • 性别: Icon_minigender_2
  • 来自: 远方
社区版块
存档分类
最新评论

CXF客户端调用

阅读更多
上一篇我用acgei绑定的方式创建了一个Web Service。后面做一个Client进行调用验证一下。
java客户端
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.mms.webservice.client;



import java.util.List;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.mms.webservice.VendorMaintenance;
import com.mrm.model.other.Vendor;


public final class ClientVendor {

    private ClientVendor() {
    }

    public static void main(String args[]) throws Exception {
        // START SNIPPET: client
        ClassPathXmlApplicationContext context 
            = new ClassPathXmlApplicationContext(new String[] {"com/tnt/mms/webservice/client/client-vendor-beans.xml"});

        
        VendorMaintenance client = (VendorMaintenance)context.getBean("client");

        Vendor ls =client.get("10116");
        System.out.println("Response: " + ls.getEngName());
        
        List<Vendor> rs=client.getList();
        System.out.println("Response: " + rs.size());
        System.out.println("Response: " + rs.get(0).getEngName());
        
        System.exit(0);
        // END SNIPPET: client
    }
}




xml配置
<?xml version="1.0" encoding="UTF-8"?>
<!--
	Licensed to the Apache Software Foundation (ASF) under one
	or more contributor license agreements. See the NOTICE file
	distributed with this work for additional information
	regarding copyright ownership. The ASF licenses this file
	to you under the Apache License, Version 2.0 (the
	"License"); you may not use this file except in compliance
	with the License. You may obtain a copy of the License at
	
	http://www.apache.org/licenses/LICENSE-2.0
	
	Unless required by applicable law or agreed to in writing,
	software distributed under the License is distributed on an
	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
	KIND, either express or implied. See the License for the
	specific language governing permissions and limitations
	under the License.
-->
<!-- START SNIPPET: beans -->
<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-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">
<!-- Configure CXF to use Aegis data binding instead of JAXB -->
	<bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding" scope="prototype"/>
	<bean id="jaxwsAndAegisServiceFactory"
	      class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
	      scope="prototype"> 
		<property name="dataBinding" ref="aegisBean"/>
		<property name="serviceConfigurations">
			<list>
				<bean class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration"/>
				<bean class="org.apache.cxf.aegis.databinding.AegisServiceConfiguration"/>
				<bean class="org.apache.cxf.service.factory.DefaultServiceConfiguration"/> 
			</list>
		</property>
	</bean>
	
    <bean id="client" class="com.tnt.mms.webservice.VendorMaintenance" 
      factory-bean="clientFactory" factory-method="create"/>
    
	<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
	  <property name="serviceClass" value="com.tnt.mms.webservice.VendorMaintenance"/>
	  <property name="address" value="http://localhost:8080/extjsmms/VendorMaintenance"/>
	  		<property name="serviceFactory" ref="jaxwsAndAegisServiceFactory"/>
	</bean>
	  
</beans>
<!-- END SNIPPET: beans -->


运行client就可以调试结果。

总结
使用Acegi进行数据绑定后,在调用的时候一样要进行对应的acegi绑定。否则数据出不来。但不知道异构系统相互调用时如何进行。以后再研究了
3
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics