如何从命令行执行SOAP wsdl Web服务调用

Mar*_*ina 78 soap wsdl

我需要对https://sandbox.mediamind.com/Eyeblaster.MediaMind.API/V2/AuthenticationService.svc?wsdl进行SOAP webservice调用,并在传递参数时使用ClientLogin操作:ApplicationKey,Password和UserName .响应是UserSecurityToken.它们都是字符串.

以下是完全解释我要做的事情的链接:https: //sandbox.mediamind.com/Eyeblaster.MediaMind.API.Doc/?v = 3

我怎么能在命令行上执行此操作?(Windows和/或Linux会很有帮助)

Tom*_*icz 129

它是一种标准的普通SOAP Web服务.SSH在这里无关.我只是用(单线)调用它:

$ 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
Run Code Online (Sandbox Code Playgroud)

其中request.xmlfile具有以下内容:

<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>
Run Code Online (Sandbox Code Playgroud)

我得到这美丽的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>
Run Code Online (Sandbox Code Playgroud)

你试过吗?

阅读更多

  • +1 soapui,一个非常有用和免费的工具,用于处理基于肥皂的Web服务.比使用命令行恕我直言好多了. (5认同)

lin*_*asy 19

在linux命令行上,您只需执行:

curl -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:"  -d @your_soap_request.xml -X POST https://ws.paymentech.net/PaymentechGateway
Run Code Online (Sandbox Code Playgroud)


bma*_*ovu 17

这是银行swift 代码的另一个示例 CURL - SOAP ( WSDL ) 请求

要求

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>'
Run Code Online (Sandbox Code Playgroud)

回复

< 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>
Run Code Online (Sandbox Code Playgroud)

  • +1 用于指示多个标题行(另一个 -H),并且将所有标题行都放在一个位置很整洁。在 SAP 环境中工作。 (2认同)

gog*_*sca 12

使用CURL:

SOAP_USER='myusername'
PASSWORD='mypassword'
AUTHENTICATION="$SOAP_USER:$PASSWORD"
URL='http://mysoapserver:8080/meeting/aws'
SOAPFILE=getCurrentMeetingStatus.txt
TIMEOUT=5
Run Code Online (Sandbox Code Playgroud)

CURL请求:

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

我用它来验证响应:

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
Run Code Online (Sandbox Code Playgroud)

  • $ USERNAME解析为我的linux用户名,在我的脚本中更改为$ USER (2认同)

Tec*_*hie 5

curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:ACTION_YOU_WANT_TO_CALL" --data @FILE_NAME URL_OF_THE_SERVICE 
Run Code Online (Sandbox Code Playgroud)

上面的命令对我很有帮助

例子

curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:urn:GetVehicleLimitedInfo" --data @request.xml http://11.22.33.231:9080/VehicleInfoQueryService.asmx 
Run Code Online (Sandbox Code Playgroud)

更多信息