您的位置:首页 > 编程语言 > Java开发

java.net.MalformedURLException: Invalid address. Endpoint address cannot be null.

2014-09-06 22:00 435 查看
import javax.jws.WebParam;

import javax.jws.WebService;

@WebService

public interface HelloWorld {

String sayHello(@WebParam(name="username")String username);

}

import javax.jws.WebService;

@WebService(serviceName="HelloWorld")

public class HelloWorldImpl implements HelloWorld {

@Override

public String sayHello(String username) {

return "Hello:"+username;

}

}

import javax.xml.ws.Endpoint;

public class Server {

/**

* @param args

*/

public static void main(String[] args) {

HelloWorld hello=new HelloWorldImpl();

String address="http://localhost:8081/ws/HelloWorldService";

Endpoint.publish(address, hello);

System.out.println("Servet start...");

}

}

import javax.xml.namespace.QName;

import javax.xml.ws.Service;

import javax.xml.ws.soap.SOAPBinding;

public class Client {

private static final QName SERVICE_NAME=new QName(

"http://endpoint.cxf.webservice.test/",//xmlns:tns="http://endpoint.cxf.webservice.test/"

"HelloWorld"//<wsdl:binding name="helloWorldServiceSoapBinding" type="tns:HelloWorldServiceInf">

);

private static final QName PORT_NAME=new QName(

"http://endpoint.cxf.webservice.test/",//xmlns:tns="http://endpoint.cxf.webservice.test/"

"HelloWorldImplPort"//<wsdl:port binding="tns:helloWorldServiceSoapBinding" name="HelloWorldServiceImplPort">

);

public static void main(String[] args) {

String endPointAddress="http://localhost:8081/ws/HelloWorldService";

Service service=Service.create(SERVICE_NAME);

service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endPointAddress);

HelloWorld inf=service.getPort(HelloWorld.class);

System.out.println(inf.sayHello("张三"));

}

}

----------------------------------------------------------------

执行Client报异常:java.net.MalformedURLException: Invalid address. Endpoint address cannot be null.

解决方法:

HelloWorld inf=service.getPort(HelloWorld.class);--------------->HelloWorld inf=service.getPort(PORT_NAME, HelloWorld.class);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐