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

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

这里是链接完全解释我正在尝试做什么: https : //sandbox.mediamind.com/Eyeblaster.MediaMind.API.Doc/?v=3

我怎么能在命令行上做到这一点? (Windows和/或Linux会有所帮助)

这是一个标准的,普通的SOAP Web服务。 SSH在这里没有什么可做的。 我只是用curl (单线)来称呼它:

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

你尝试过soapui吗?

阅读更多

在Linux命令行上,您可以简单地执行:

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

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

我用这个使用CURL:

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

CURL请求:

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

我用这个来validation回应:

 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 

对于Windows我发现这个工作:

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

参考: CodeProject

 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 

更多信息