我试图弄清楚如何使用groovy-wslite将PHP SOAP客户端转换为Groovy。我的PHP代码看起来像这样
<?php
define ('WSDL','https://….wsdl');
define ('EndPoint','https://…');
define ('URI','urn:ws.….com');
$client = new SoapClient(WSDL,array(
'location' => EndPoint,
'uri' => URI,
'trace' => TRUE,
));
try
{
$user="…";
$pass="…";
//parameters passed as array
$loginResult = $client->login(array("username"=>"$user", "password"=>"$pass")); //session ID and jsession returned from this call
print "<br>Logging In: Success!. <br>";
print "<br>The session id is {$loginResult->result->sessionId}<br>";
}
catch (SoapFault $err) {
print "failed!\n";
print "Login Error: ".$err->faultString."\n";
$loggedIN = false;
}
?>
以下是一些示例groovy代码(可行),我试图将代码放入其中。
@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='0.8.0')
import wslite.soap.*
def client = new SOAPClient('http://www.holidaywebservice.com/Holidays/US/Dates/USHolidayDates.asmx')
def response = client.send(SOAPAction:'http://www.27seconds.com/Holidays/US/Dates/GetMothersDay') {
body {
GetMothersDay('xmlns':'http://www.27seconds.com/Holidays/US/Dates/') {
year(2011)
}
}
}
这是我尝试合并两个
时开始的代码@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='0.8.0')
import wslite.soap.*
def client = new SOAPClient('<EndPoint>')
def response = client.send(SOAPAction:'login') {
body {
login('xmlns':'[what do I put here]') {
username("<user>"),
password("<pass>")
}
}
}
所以我认为我用我的EndPoint替换了SOAPClient,但是当我到达Groovy代码的SOAPAction和body部分时,我有点失去它。
任何人都可以帮我将PHP代码转换为Groovy-wslite等价物吗?
答案 0 :(得分:0)
经过多次试验和错误后,我登录了
@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='0.8.0')
import wslite.soap.*
def client = new SOAPClient(<EndPoint>)
def response = client.send(SOAPAction:<EndPoint>) {
body {
login('xmlns':<URI>) {[
username(<user>),
password(<pass>)
]}
}
}