我的计算机上运行了2个Web服务。
我做的简单的HelloWorld Java WebService。
WSDL:
其他人制作的更复杂的C#WebService。
WSDL:
现在我用Java构建了两个客户端,用于使用每个Web服务:
HelloWorld Java WebService的客户端代码:
package com.mykong.ws;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import com.mykong.ws.HelloWorld;
public class HelloWorldClient{
public static void main(String[] args) throws Exception {
URL url = new URL("http://localhost:9999/ws/hello?wsdl");
QName qname = new QName("http://ws.mykong.com/", "HelloWorldImplService");
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);
System.out.println(hello.getHelloWorldAsString("mkyong"));
}
}
客户端编码由其他人制作的更复杂的C#WebService:
package TESTE;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class Main {
public static void main(String[] args) throws MalformedURLException {
URL wsdlLocation = new URL("http://localhost:8000/eamsLink/RepositoryService/?wsdl");
QName qname = new QName("http://tempuri.org/", "RemoteSourceService");
Service.create(wsdlLocation, qname);
}
}
当我运行Hello世界的客户端时,没有任何问题,但是当我尝试运行其他客户端并且当它到达Service.create(...)时出现问题,它会中断并给出NullPointerException,正如您在以下代码中看到的那样:
Exception in thread "main" java.lang.NullPointerException
at com.sun.xml.internal.ws.model.wsdl.WSDLOperationImpl.freeze(Unknown Source)
at com.sun.xml.internal.ws.model.wsdl.WSDLPortTypeImpl.freeze(Unknown Source)
at com.sun.xml.internal.ws.model.wsdl.WSDLBoundPortTypeImpl.freeze(Unknown Source)
at com.sun.xml.internal.ws.model.wsdl.WSDLModelImpl.freeze(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(Unknown Source)
at javax.xml.ws.Service.<init>(Unknown Source)
at javax.xml.ws.Service.create(Unknown Source)
at TESTE.Main.main(Main.java:18)
有人真的能帮帮我吗?
答案 0 :(得分:0)
从WSDLs看,Java Web Service似乎使用SOAP 1.1,而.NET Web Service使用soap Version 1.2。在调用服务时,您必须考虑到这一点。尝试使用
service.addPort(QName portName, String SOAPBinding.SOAP12HTTP_BINDING, String endpointAddress);