Come eseguire una chiamata ai servizi Web SOAP wsdl dalla riga di comando


92

Devo effettuare una chiamata al servizio web SOAP a https://sandbox.mediamind.com/Eyeblaster.MediaMind.API/V2/AuthenticationService.svc?wsdl e utilizzare l'operazione ClientLogin passando attraverso i parametri: ApplicationKey, Password e UserName . La risposta è UserSecurityToken. Sono tutte corde.

Ecco il link che spiega completamente cosa sto cercando di fare: https://sandbox.mediamind.com/Eyeblaster.MediaMind.API.Doc/?v=3

Come posso farlo dalla riga di comando? (Windows e / o Linux sarebbero utili)

Risposte:


146

È un servizio web SOAP standard e ordinario. SSH non ha niente a che fare qui. L'ho appena chiamato con (una riga):

$ curl -X POST -H "Content-Type: text/xml" \
    -H 'SOAPAction: "http://api.eyeblaster.com/IAuthenticationService/ClientLogin"' \
    --data-binary @request.xml \
    https://sandbox.mediamind.com/Eyeblaster.MediaMind.API/V2/AuthenticationService.svc

Dove il request.xmlfile ha il seguente contenuto:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.eyeblaster.com/">
           <soapenv:Header/>
           <soapenv:Body>
              <api:ClientLogin>
                 <api:username>user</api:username>
                 <api:password>password</api:password>
                 <api:applicationKey>key</api:applicationKey>
              </api:ClientLogin>
          </soapenv:Body>
</soapenv:Envelope>

Ho questa bellissima 500:

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <s:Fault>
      <faultcode>s:Security.Authentication.UserPassIncorrect</faultcode>
      <faultstring xml:lang="en-US">The username, password or application key is incorrect.</faultstring>
    </s:Fault>
  </s:Body>
</s:Envelope>

Hai provato ?

Leggi di più


6
+1 soapui, uno strumento molto utile e gratuito per lavorare con servizi web basati su soap. Molto meglio dell'utilizzo della riga di comando IMHO.
Analisi fuzzy

Quale versione di curl stai usando? Il mio dice "Impossibile risolvere l'host" --data-binary "e che https è un" protocollo non supportato ".
Marina

Se faccio esattamente quello che hai fatto, ricevo sempre un errore da mediamind che dice che "Si è verificato un errore interno imprevisto del server". C'è qualcosa che non hai incluso nella risposta che dovrei fare (oltre a sostituire il tasto un / pw / con quelli reali)?
Marina

@ Marina: ora ricevo anche " 500 Internal Server Error ". Tuttavia questo è un errore lato server, non nostro (?), Chiedi al provider WS cosa sta succedendo. Funzionava pochi giorni fa.
Tomasz Nurkiewicz

Grazie per la tua risposta. Manca un / Envelope in request.xml, che causa una risposta di errore dal server. Una volta ho aggiunto che ha funzionato bene. Forse questo è il problema per altre persone che ottengono errori.
apadana

24

Sulla riga di comando di Linux, puoi semplicemente eseguire:

curl -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:"  -d @your_soap_request.xml -X POST https://ws.paymentech.net/PaymentechGateway

13

Utilizzando CURL:

SOAP_USER='myusername'
PASSWORD='mypassword'
AUTHENTICATION="$SOAP_USER:$PASSWORD"
URL='http://mysoapserver:8080/meeting/aws'
SOAPFILE=getCurrentMeetingStatus.txt
TIMEOUT=5

Richiesta CURL:

curl --user "${AUTHENTICATION}" --header 'Content-Type: text/xml;charset=UTF-8' --data @"${SOAPFILE}" "${URL}" --connect-timeout $TIMEOUT

Lo uso per verificare la risposta:

http_code=$(curl --write-out "%{http_code}\n" --silent --user "${AUTHENTICATION}" --header 'Content-Type: text/xml;charset=UTF-8' --data @"${SOAPFILE}" "${URL}" --connect-timeout $TIMEOUT --output /dev/null)
if [[ $http_code -gt 400 ]];  # 400 and 500 Client and Server Error codes http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
then
echo "Error: HTTP response ($http_code) getting URL: $URL"
echo "Please verify parameters/backend. Username: $SOAP_USER Password: $PASSWORD Press any key to continue..."
read entervalue || continue
fi

2
$ USERNAME si risolve nel mio nome utente Linux, cambiato in $ USER nei miei script
DmitrySandalov

12

Ecco un altro esempio di richiesta CURL - SOAP ( WSDL ) per codici swift bancari

Richiesta

curl -X POST http://www.thomas-bayer.com/axis2/services/BLZService \
  -H 'Content-Type: text/xml' \
  -H 'SOAPAction: blz:getBank' \
  -d '
  <soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:blz="http://thomas-bayer.com/blz/">
    <soapenv:Header/>
    <soapenv:Body>
      <blz:getBank>
        <blz:blz>10020200</blz:blz>
      </blz:getBank>
    </soapenv:Body>
  </soapenv:Envelope>'

Risposta

< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: text/xml;charset=UTF-8
< Date: Tue, 26 Mar 2019 08:14:59 GMT
< Content-Length: 395
< 
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <ns1:getBankResponse
      xmlns:ns1="http://thomas-bayer.com/blz/">
      <ns1:details>
        <ns1:bezeichnung>BHF-BANK</ns1:bezeichnung>
        <ns1:bic>BHFBDEFF100</ns1:bic>
        <ns1:ort>Berlin</ns1:ort>
        <ns1:plz>10117</ns1:plz>
      </ns1:details>
    </ns1:getBankResponse>
  </soapenv:Body>
</soapenv:Envelope>

1
+1 per indicare diverse righe di intestazione (un'altra -H) e poiché è normale avere tutte in un'unica posizione. Ha lavorato nel contesto SAP.
fino

5
curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:ACTION_YOU_WANT_TO_CALL" --data @FILE_NAME URL_OF_THE_SERVICE 

Il comando sopra è stato utile per me

Esempio

curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:urn:GetVehicleLimitedInfo" --data @request.xml http://11.22.33.231:9080/VehicleInfoQueryService.asmx 

Ulteriori informazioni


3

Per gli utenti Windows che cercano un'alternativa a PowerShell, eccola qui (utilizzando POST). L'ho diviso su più righe per leggibilità.

$url = 'https://sandbox.mediamind.com/Eyeblaster.MediaMind.API/V2/AuthenticationService.svc'
$headers = @{
    'Content-Type' = 'text/xml';
    'SOAPAction' = 'http://api.eyeblaster.com/IAuthenticationService/ClientLogin'
}
$envelope = @'
    <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
        <Body>
            <yourEnvelopeContentsHere/>
        </Body>
    </Envelope>
'@     # <--- This line must not be indented

Invoke-WebRequest -Uri $url -Headers $headers -Method POST -Body $envelope

2

Per Windows:

Salva quanto segue come MSFT.vbs:

set SOAPClient = createobject("MSSOAP.SOAPClient")
SOAPClient.mssoapinit "https://sandbox.mediamind.com/Eyeblaster.MediaMind.API/V2/AuthenticationService.svc?wsdl"
WScript.Echo "MSFT = " & SOAPClient.GetQuote("MSFT")

Quindi da un prompt dei comandi, esegui:

C:\>MSFT.vbs

Riferimento: http://blogs.msdn.com/b/bgroth/archive/2004/10/21/246155.aspx


1
La tecnica di quest'anno 2004 fallisce almeno su Windows 7.
Aram Paronikyan

2

Per Windows ho trovato che funziona:

Set http = CreateObject("Microsoft.XmlHttp")
http.open "GET", "http://www.mywebservice.com/webmethod.asmx?WSDL", FALSE
http.send ""
WScript.Echo http.responseText

Riferimento: CodeProject

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.