【问题标题】:How do I use a soap xml based webservice in javascript over a secure https connection?如何通过安全的 https 连接在 javascript 中使用基于 soap xml 的 web 服务?
【发布时间】:2012-09-10 07:31:23
【问题描述】:

我想在 JavaScript 中使用 XML SOAP 网络服务来创建 Firefox 插件,但我想使用的网络服务是在安全的 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 消息时,会显示警报('ERROR'),并且 Firefox 的 firebug 插件会显示此消息。

Error de lectura XML: no se encuentra elemento Ubicación: moz-nullprincipal:{fc98c066-ae21-4b57-b743-83e9519342c7} 编号 第 1 行,第 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 中,如果我使用其他服务,脚本可以工作。

【问题讨论】:

  • 通过 javascript,除非服务器支持 CORS,否则您可能会遇到 CROSS-DOMAIN 错误。 P.S. 链接无处可去。
  • ups,该链接仅适用于我的大学
  • 那么你在做那个插件时会遇到很大的问题... ;)
  • 我认为服务器不需要 CORS,因为我将使用来自同一个域的服务。

标签: javascript web-services firefox soap firefox-addon


【解决方案1】:

如果您不关心跨域,那么您可以尝试一下...我将使用 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;
});

【讨论】:

    猜你喜欢
    • 2013-10-10
    • 2016-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多