微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WebService的server与client代码

server:

 

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsServerfactorybean;

public class SoapServer {

    public static void main(String[] args) {
        System.out.println("web service started...");
       
        //Endpoint.publish("http://127.0.0.1:8080/helloService",new HelloServiceImpl());
       
        JaxWsServerfactorybean soapfafactorybean = new JaxWsServerfactorybean();
        soapfafactorybean.setAddress("http://127.0.0.1:8080/helloService");
        soapfafactorybean.getininterceptors().add(new LoggingInInterceptor());
        soapfafactorybean.getoutInterceptors().add(new LoggingOutInterceptor());
        soapfafactorybean.setServiceClass(HelloServiceImpl.class);
        soapfafactorybean.create();
       
    }
   
}

 

 

 

 

client:

import java.net.MalformedURLException; import java.net.URL; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.GregorianCalendar; import javax.xml.namespace.QName; import org.apache.cxf.jaxws.JaxWsProxyfactorybean; import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl; public class SoapCLient {     public static void main(String[] args) throws ParseException,MalformedURLException {         /*         JaxWsProxyfactorybean soapfactorybean = new JaxWsProxyfactorybean();         soapfactorybean.setAddress("http://127.0.0.1:8080/helloService");         soapfactorybean.setServiceClass(IHelloService.class);         Object o = soapfactorybean.create();         IHelloService helloService = (IHelloService) o;         Customer c1 = new Customer();         c1.setId(1);         c1.setName("A");         GregorianCalendar calendar = (GregorianCalendar) GregorianCalendar.getInstance();         calendar.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("1989-01-28"));         c1.setBirthday(new XMLGregorianCalendarImpl(calendar));         Customer c2 = new Customer();         c2.setId(2);         c2.setName("B");         calendar.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("1990-01-28"));         c2.setBirthday(new XMLGregorianCalendarImpl(calendar));                 System.out.println(helloService.selectMaxAgeStudent(c1,c2).getName());                 */                 QName qName = new QName("http://server.soap.hjx.com","HelloServiceImplService");         HelloServiceImplService helloServiceImplService = new HelloServiceImplService(new URL("http://127.0.0.1:8080/helloService?wsdl"),qName);         IHelloService helloService = helloServiceImplService.getPort(IHelloService.class);     } }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐