需要帮助使用groovy-wslite将PHP SOAP代码转换为Groovy [英] Need help converting PHP SOAP code to Groovy using groovy-wslite

查看:76
本文介绍了需要帮助使用groovy-wslite将PHP SOAP代码转换为Groovy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何使用groovy-wslite将PHP SOAP客户端转换为Groovy.我拥有的PHP代码如下所示:

I'm trying to figure out how to convert a PHP SOAP client over to Groovy using groovy-wslite. The PHP code I have looks like this

<?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;
}

?>

这是一些示例代码(有效),我正在尝试使其适合我的代码.

Here is some example groovy code (that works) which I'm trying to fit my code into.

@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)
        }
    }
}

这是我尝试将两者合并时开始的代码

Here is the code I started when I attempted to merge the two

@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和主体部分时,我有点迷失了.

So I think I replace the SOAPClient with my EndPoint, but I kind of lose it when I get to the SOAPAction and body portions of the Groovy code.

有人可以帮助我将PHP代码转换为Groovy-wslite等效项吗?

Can anyone help me convert the PHP code to the Groovy-wslite equivalent?

推荐答案

经过反复尝试,我使登录正常工作

After much trial and error I got the login working

@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>)
        ]}
    }
}

这篇关于需要帮助使用groovy-wslite将PHP SOAP代码转换为Groovy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆