Consume a PHP Web Service from Java Desktop

1

In order to connect to the WS, the credentials and the method have passed me. Previously I had the WS Style error that was RPC, I solved it by adding a plugin to Netbeans.

Now when I put the URL of the WS, NetBeans starts loading and shows an error WsCompile .

When I click OK, I see that in my Project directory, I have not created any files, and in Web Service References it appears: "Parsing WSDL ...".

I have tried with some Axis2, but I can not implement it to NetBeans, nor use it.

To try to facilitate the use of the WS I decided to try to recreate the WS, getting to know that the WS that I try to use is made with the PHP Nusoap library , and I see it impossible to pass the credentials without the use of this library that is only for the Web. Given this I think to ask the developer of the WS that can pass the credentials by means of parameters.

Now that I have recreated the WS locally, I tried to do my tests with NetBeans and it shows the error that the type of Response that in my case is a Array is not recognized, and the response files are encoded with ISO-8859-1 .

This is the XML:

<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:wssalud"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:wssalud">
  <types>
    <xsd:schema targetNamespace="urn:wssalud">
      <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
      <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
    </xsd:schema>
  </types>
  <message name="get_busafi_activoRequest">
    <part name="nroDoc" type="xsd:string" />
  </message>
  <message name="get_busafi_activoResponse">
    <part name="return" type="xsd:Array" />
  </message>
  <portType name="wssaludPortType">
    <operation name="get_busafi_activo">
      <documentation>Web Service Datos Afiliado</documentation>
      <input message="tns:get_busafi_activoRequest" />
      <output message="tns:get_busafi_activoResponse" />
    </operation>
  </portType>
  <binding name="wssaludBinding" type="tns:wssaludPortType">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
    <operation name="get_busafi_activo">
      <soap:operation soapAction="urn:wssalud#get_busafi_activo" style="rpc" />
      <input>
      <soap:body use="encoded" namespace="urn:wssalud" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
      </input>
      <output>
<soap:body use="encoded" namespace="urn:wssalud" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
    </operation>
  </binding>
  <service name="wssalud">
    <port name="wssaludPort" binding="tns:wssaludBinding">
      <soap:address location="http://sitioweb.com/ws/ws_AfiliadoSPHLNS.php" />
    </port>
  </service>
</definitions>

I do not know if there will be someone who has had these problems with a Java Desktop Application.

Additional information: Use NetBeans 8.2

    
asked by NealBustamante 21.06.2017 в 18:37
source

1 answer

0

We do not use netbeans well, but to make a WS java client you only need these steps in eclipse:

  • create a normal java project and then right click-> new Web Service client- >

  • paste the url or wsdl file and download the toolbar to Develop Client

  • This generates several files. The class that must be instantiated to consume the Web service soap is always the one that terminates proxy.

  • Example:

    public class ClienteSoapJava {
        public static void main(String[] args)throws RemoteException{
            ConversionServiceProxy servicio=new ConversionServiceProxy();//Clase que se genero automaticamente al pegar la url del WSDL (el nombre puede cambiar pero termina en proxy)
            double conversion=servicio.conversionRate("USD", "MXN");//Metodo del WS que estoy invocando. (El nombre del metodo siempre es distinto)
            System.out.println(conversion);
        }
    }
    

    It does not matter if the WS is done in java, php, or c #, the way to create the WS client will always be the same.

        
    answered by 21.06.2017 в 19:45