簡體   English   中英

如何通過安全的https連接在JavaScript中使用基於soap xml的Web服務?

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

我想在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中發送肥皂消息時,會顯示alert('ERROR'),並且Firefox的firebug插件會顯示此消息。

錯誤的lectura XML:沒有本質的支持。文本:moz-nullprincipal:{fc98c066-ae21-4b57-b743-83e9519342c7}Númerodelínea1,第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;
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM