简体   繁体   中英

How do I use a soap xml based webservice in javascript over a secure https connection?

I want to use a XML SOAP web service in JavaScript to create a Firefox Addon, but the web service I want to use is under a secure https connection.

https://cuotas.uci.cu:443/servicios/v1/InetCuotasWS.wsdl

The soapclient.js library that I downloaded doesn't work with a secure connection. How can I solve this problem? Are there any existing useful JS libraries?

EDIT: This is what is shown in the link

<!-- WSDL file generated by Zend Studio. --><definitions name="InetCuotasWS" targetNamespace="urn:InetCuotasWS">
<types><xsd:schema targetNamespace="urn:InetCuotasWS">
<xsd:complexType name="Usuario"><xsd:all>
<xsd:element name="cuota" type="xsd:float"/><xsd:element name="cuota_usada" type="xsd:anyType"/>
<xsd:element name="nivel_navegacion" type="xsd:string"/>
<xsd:element name="usuario" type="xsd:string"/>
</xsd:all></xsd:complexType></xsd:schema></types>
<message name="ObtenerCuota"><part name="usuario" type="xsd:string"/><part name="clave" type="xsd:string"/>
<part name="dominio" type="xsd:string"/></message>
<message name="ObtenerCuotaResponse"><part name="ObtenerCuotaReturn" type="typens:Usuario"/></message><portType name="InetCuotasWSPortType">
<operation name="ObtenerCuota"><documentation>
            Obtener el estado de la cuota de un usuario dado su usuario y clave.
        </documentation>
<input message="typens:ObtenerCuota"/>
<output message="typens:ObtenerCuotaResponse"/></operation></portType><binding name="InetCuotasWSBinding" type="typens:InetCuotasWSPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="ObtenerCuota"><soap:operation soapAction="urn:InetCuotasWSAction"/><input><soap:body namespace="urn:InetCuotasWS" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input><output><soap:body namespace="urn:InetCuotasWS" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output></operation></binding><service name="InetCuotasWSService"><port name="InetCuotasWSPort" binding="typens:InetCuotasWSBinding"><soap:address location="https://cuotas.uci.cu/servicios/v1/InetCuotasWS.php"/>
</port></service></definitions>

EDIT I used SoapUI as you said, this is the URI https://cuotas.uci.cu/servicios/v1/InetCuotasWS.php?wsdl And SoapMessage is

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:InetCuotasWS">
<soapenv:Header/><soapenv:Body>
<urn:ObtenerCuota soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<usuario xsi:type="xsd:string">dogcalas</usuario>
<clave xsi:type="xsd:string">.*Pepe</clave>
<dominio xsi:type="xsd:string">uci</dominio>
</urn:ObtenerCuota></soapenv:Body></soapenv:Envelope>    

When I send the soap message in Firefox, the alert('ERROR') is shown and Firefox´s firebug addon shows this message.

Error de lectura XML: no se encuentra elemento Ubicación: moz-nullprincipal:{fc98c066-ae21-4b57-b743-83e9519342c7} Número de línea 1, columna 1:

Even using another service, Firefox always shows the same message. Only when I use Internet Explorer 10, the message is sent, but the server response isn´t what I expect:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Client</faultcode>
<faultstring>SoapClient::SoapClient() [&lt;a href='soapclient.soapclient'&gt;soapclient.soapclient&lt;/a&gt;]: 'location' and 'uri' options are required in nonWSDL mode</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

In IE, if I use another service, the script works.

If you are not concern about Cross-Domain, then you can give this a try... I'll use jQuery as it's way simpler, you would have to convert to your own syntax if you have to as I never did Mozilla Plugins.

Note: you need to get the correct URL for the call, and the correct Soap Message

For this, I would suggest you install SoapUI and connect to the service, you will get all raw information needed to send and receive information

var webServiceURL = 'https://cuotas.uci.cu:443/servicios/v1/InetCuotasWS?op=ObtenerCuota';
var soapMessage = '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:Body><ObtenerCuota xmlns="http://tempuri.org/" /></soap12:Body></soap12:Envelope>';

function CallService()
{
    $.ajax({
        url: webServiceURL, 
        type: "POST",
        dataType: "xml", 
        data: soapMessage, 
        contentType: "text/xml; charset=\"utf-8\"",
        success: OnSuccess, 
        error: OnError
    });

    return false;
}

function OnSuccess(data, status)
{
    alert(data.d);
}

function OnError(request, status, error)
{
    alert('error');
}

$(function() {
    jQuery.support.cors = true;
});

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