I am unable to access a Webservice written in C#, from Java

Asked

Viewed 115 times

0

I have a Webservice written C# and need to connect to it from Java to invoke some methods.

It is possible?

import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;


public class SoapClient {

    public static void main(String[] args) {

        URL wsdlLocation = null;
        try {
            wsdlLocation = new URL("http://localhost:8000/eamsLink/RepositoryService/?wsdl");
        } catch (MalformedURLException ex) {
            Logger.getLogger(SoapClient.class.getName()).log(Level.SEVERE, null, ex);
        }


        QName qname = new QName("http://tempuri.org/", "RemoteSourceService");

        Service service = Service.create(wsdlLocation, qname);
    }
}

I’m trying this way but I’m having this error on the console:

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 SoapClient.main(SoapClient.java:22)

1 answer

0


recommend using JAX WS and CXF to make calls to Webservice in java is much simpler.

Example link - Using Eclipse

Otherwise, if you are not using Eclipse IDE, it can be executed by generating the stubs of the wsdl-based class and then run as if it were in . NET.

Run this command at the prompt, where your consumer’s source code is.

wsimport -Keep -p com.acme.client http://localhost:8000/eamsLink/Repositoryservice/? wsdl

Change with.acme.client for your package.

In this case wsimport should generate some classes. java on-site, as per your service specification, so you must have an Implservice.java file and you must make the instantiation of this service and the call of your method, you can see an example www.thejavageek.com/2015/01/28/using-wsimport-command-generate-web-service-client.

I hope I’ve helped.

  • I’ve changed my strategy. I’ll have to create a "Gateway" between Java and C# Webservice. Serving Java and Gateway as server and client, each. Can you help me out here?

  • Can you explain to me better your need? Will you create a gateway or proxy for the web service in c#? This will look like Java -> Gateway (Java) -> Webservice?

  • we can talk in some chat?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.