简体   繁体   中英

Can't create a Java Client and connect it to C# WebService

I have on my computer 2 web services running.

Simple HelloWorld Java WebService made by me.

WSDL:

More complex C# WebService made by other guys.

WSDL:

And now I have build 2 clients, in Java, for consuming each of the WebServices:

Client code for the 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"));

    }

}

Client code the more complex C# WebService made by others guys:

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);


    }

}

When I run the client of the Hello world there is no problem with it, but the problem arises when I try to run the other client and when it reaches the Service.create(...) it breaks and gives NullPointerException, as you can see in the following code:

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)

Can someone really help me out please?

From the WSDLs it seems that the Java Web Service uses SOAP 1.1 whereas the .NET Web Service uses soap Version 1.2. You have to account for that when calling the service. try using

service.addPort(QName portName, String SOAPBinding.SOAP12HTTP_BINDING, String endpointAddress);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM