-1

I'm trying to invoke an old Java XML WS according to some documentation the provider gives. Here's the thing. At some point, I need to create a java service and call it's .getPort() function but it expects a java.lang.class object and I'm having an interface myself.

public ServiceResponse CallFileUploadService(List<BatchFile> batchFiles)
    {
        ServiceResponse resp = new ServiceResponse();
        try
        {
            URL url = new URL(configuration.Endpoints.CallFileUploadService_Url);
            QName qname = new QName(configuration.Endpoints.CallFileUploadService_QName, "FileUploadWebService");
            Service service = Service.create(url, qname);

            IFileUploadWebService ws = service.getPort(typeof(IFileUploadWebService)); // GETTING ERROR HERE
        }
        catch (Exception ex)
        {
            Utilities.Print($"Error en la llamada al servicio web. Ver detalles:\n{ex.Message}\n\n{ex.StackTrace}", true);
        }
    }

Error says: enter image description here

Objects url, qname and service are java objects.

Any help is appreciated!

mrbitzilla
  • 368
  • 3
  • 11

1 Answers1

0

After some trial and error managed to solve it this way. It was fairly simple at the end, just with a cast:

public ServiceResponse CallFileUploadService(List<BatchFile> batchFiles)
{
    ServiceResponse resp = new ServiceResponse();
    try
    {
        URL url = new URL(configuration.Endpoints.CallFileUploadService_Url);
        QName qname = new QName(configuration.Endpoints.CallFileUploadService_QName, "FileUploadWebService");
        Service service = Service.create(url, qname);

        IFileUploadWebService ws = (IFileUploadWebService)service.getPort(typeof(IFileUploadWebService)); // GETTING ERROR HERE
    }
    catch (Exception ex)
    {
        Utilities.Print($"Error en la llamada al servicio web. Ver detalles:\n{ex.Message}\n\n{ex.StackTrace}", true);
    }
}
mrbitzilla
  • 368
  • 3
  • 11
  • Just like the error message said ("... are you missing a cast?"). Be glad that you're not working in C++ where the error messages are diabolically perverse. – Dave Doknjas May 24 '20 at 21:57
  • Yes. I was trying the cast on the getPort() object that was being sent but just tried with the whole thing and worked out. – mrbitzilla May 25 '20 at 03:01