javascript - 如何通过安全的 https 连接在 javascript 中使用基于 SOAP XML 的 Web 服务?

标签 javascript web-services firefox soap firefox-addon

我想在 JavaScript 中使用 XML SOAP Web 服务来创建 Firefox 插件,但我想使用的 Web 服务位于安全的 https 连接下。

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

我下载的soapclient.js 库无法在安全连接下运行。我怎么解决这个问题?有没有现成的有用的 JS 库?

编辑: 这是链接中显示的内容

<!-- 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>

编辑 正如你所说,我使用了 SoapUI,这是 URI https://cuotas.uci.cu/servicios/v1/InetCuotasWS.php?wsdl SoapMessage 是

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

当我在 Firefox 中发送 SOAP 消息时,会显示警报(“错误”),并且 Firefox 的 firebug 插件会显示此消息。

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:

即使使用其他服务,Firefox 也始终显示相同的消息。 仅当我使用 Internet Explorer 10 时,才会发送消息,但服务器响应不是我所期望的:

<?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>

在 IE 中,如果我使用其他服务,该脚本就可以工作。

最佳答案

如果您不关心跨域,那么您可以尝试一下...我将使用 jQuery,因为它更简单,如果需要的话,您必须转换为您自己的语法,而我从未这样做过Mozilla 插件。

注意:您需要获取调用的正确URL以及正确的Soap Message

为此,我建议您安装SoapUI并连接到该服务,您将获得发送和接收信息所需的所有原始信息

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

关于javascript - 如何通过安全的 https 连接在 javascript 中使用基于 SOAP XML 的 Web 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12347092/

相关文章:

javascript - 给调色板元素边框或标题

java - Netbeans 的 Eclipse Web 服务资源管理器的替代方案

sql - 动态更新SSIS中Web服务任务中的wsdl文件

javascript - Firefox event.clientX 无法运行

javascript - 使用 rowspan 删除多个选定的行

javascript - 有没有一种方法可以仅将 Gatsby 用于静态 html 文件而不使用 webpacked javascript 文件?

javascript - 深入搜索属性值后返回对象

android - 通过 android 将图像上传到 RESTful web 服务,给出 NoSuchMethodError

jquery - 将类添加到正文时不触发 CSS 转换 (Firefox)

firefox - Mozilla Firefox 的制作涉及哪些技术?