2012-08-31 111 views
41

我需要對https://sandbox.mediamind.com/Eyeblaster.MediaMind.API/V2/AuthenticationService.svc?wsdl進行SOAP webservice調用,並在傳遞參數時使用ClientLogin操作:ApplicationKey,Password和UserName。響應是UserSecurityToken。他們都是字符串。如何從命令行執行SOAP wsdl Web服務調用

這裏是鏈接完全解釋什麼,我試圖做的: https://sandbox.mediamind.com/Eyeblaster.MediaMind.API.Doc/?v=3

我怎樣才能做到這一點的命令行? (Windows和/或Linux會有所幫助)

回答

77

這是一種標準的普通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 

request.xml文件具有以下內容:

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

我得到這個美麗的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> 

你試過

Read more

+3

+1 soapui,一個用於使用基於soap的web服務的非常有用且免費的工具。比使用命令行恕我直言更好。 – fuzzyanalysis

+0

您使用的是哪個版本的捲髮? Mine說:「無法解析主機'--data-binary',並且https是一個」Unsupported protocol「 – Marina

+0

如果我確實做了你所做的,那麼我總是會從mediamind中得到一個錯誤,服務器錯誤發生了。「是否有任何事情你沒有包括在我應該做的答案中(除了用真正的代替un/pw/key)? – Marina

2

對於Windows:

以下內容作爲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") 
從命令提示符

,然後運行:

C:\>MSFT.vbs 

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

+1

至少2004年,2004年的技術在Window 7上失敗。 –

+0

試試Powershell。 – fuzzyanalysis

2

我用這個使用curl:

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

捲曲要求:

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

我使用它來驗證響應:

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: $USER Password: $PASSWORD Press any key to continue..." 
read entervalue || continue 
fi 
+1

$ USERNAME解析爲我的Linux用戶名,在我的腳本中更改爲$ USER – DmitrySandalov

7

在Linux命令行,你可以簡單地執行:

curl -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:" -d @your_soap_request.xml -X POST https://ws.paymentech.net/PaymentechGateway 
1
curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:ACTION_YOU_WANT_TO_CALL" --data @FILE_NAME URL_OF_THE_SERVICE 

上面的命令是有幫助的,我

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

More info

1

對於Windows,我發現這個工作:

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

參考:CodeProject