81,094
社区成员
发帖
与我相关
我的任务
分享
package net.nysit.webservice.impl;
/**
* Please modify this class to meet your needs
* This class is not complete
*/
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
/**
* This class was generated by Apache CXF 2.4.2
* 2012-05-21T15:32:19.203+08:00
* Generated source version: 2.4.2
*
*/
public final class HelloWorldImpl_HelloWorldImplPort_Client {
private static final QName SERVICE_NAME = new QName("http://impl.webservice.nysit.net/", "HelloWorldImplService");
private HelloWorldImpl_HelloWorldImplPort_Client() {
}
public static void main(String args[]) throws java.lang.Exception {
URL wsdlURL = HelloWorldImplService.WSDL_LOCATION;
if (args.length > 0 && args[0] != null && !"".equals(args[0])) {
File wsdlFile = new File(args[0]);
try {
if (wsdlFile.exists()) {
wsdlURL = wsdlFile.toURI().toURL();
} else {
wsdlURL = new URL(args[0]);
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
HelloWorldImplService ss = new HelloWorldImplService(wsdlURL, SERVICE_NAME);
HelloWorldImpl port = ss.getHelloWorldImplPort();
{
System.out.println("Invoking sayHello...");
java.lang.String _sayHello_arg0 = "_sayHello_arg016054355";
java.lang.String _sayHello__return = port.sayHello(_sayHello_arg0);
System.out.println("sayHello.result=" + _sayHello__return);
}
System.exit(0);
}
}
public class CaseTest {
/**
* @param args
*/
public static void main(String[] args) {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(HelloWorldImpl.class);
factory.setAddress("http://localhost/TestWebservice1/services/HelloWorldImplPort?wsdl");
// 记录入站消息
factory.getInInterceptors().add(new LoggingInInterceptor());
// 记录出站消息
factory.getOutInterceptors().add(new LoggingOutInterceptor());
if (factory.getProperties() == null) {
Map<String, Object> properties = new HashMap<String, Object>();
factory.setProperties(properties);
}
factory.getProperties().put("set-jaxb-validation-event-handler",
"false");
HelloWorldImpl client = (HelloWorldImpl) factory.create();
String result = client.sayHello("张三");
System.out.println(result);
}
}
主要是其中的factory.getProperties().put("set-jaxb-validation-event-handler",
@WebMethod(operationName = "sayHello", action = "urn:SayHello")
@WebResult(targetNamespace = "")
@RequestWrapper(className = "net.nysit.webservice.impl.jaxws.SayHello", localName = "sayHello", targetNamespace = "http://impl.webservice.nysit.net/")
@ResponseWrapper(className = "net.nysit.webservice.impl.jaxws.SayHelloResponse", localName = "sayHelloResponse", targetNamespace = "http://impl.webservice.nysit.net/")
public String sayHello(@WebParam(name = "arg0") String name) {
// TODO Auto-generated method stub
return "你好!" + name;
}
package net.nysit.webservice.impl;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
import net.nysit.webservice.HelloWorld;
@WebService(targetNamespace = "http://impl.webservice.nysit.net/", portName = "HelloWorldImplPort", serviceName = "HelloWorldImplService")
public class HelloWorldImpl implements HelloWorld {
@WebMethod(operationName = "sayHello", action = "urn:SayHello")
@RequestWrapper(className = "net.nysit.webservice.impl.jaxws.SayHello", localName = "sayHello", targetNamespace = "http://impl.webservice.nysit.net/")
@ResponseWrapper(className = "net.nysit.webservice.impl.jaxws.SayHelloResponse", localName = "sayHelloResponse", targetNamespace = "http://impl.webservice.nysit.net/")
public String sayHello(@WebParam(name = "arg0") String name) {
// TODO Auto-generated method stub
return "你好!" + name;
}
}