Search code examples
javaweb-servicessoapwsdl

Get value from soap call


Hi i am working on a java project for soap call. I have extracted the soap WSDL file from server and included in my eclipse java project.In one of the soap method for generating token from server i need to pass user name and password to a soap method called logon, and it returns the session token however the logon method return the session token using "mode=Mode.OUT" and some holder element. the query \is

        String sessiontoken ="";
        String strLogin="admin";
        String strPassword="password";
        Element elemParameters= null ;
        Holder<String> pstrSessionToken = new Holder<String>();
        Holder<Element> pSessionInfo = new Holder<Element>();
        Holder<String> pstrSecurityToken = new Holder<String>();

token_soap.logon(sessiontoken, strLogin, strPassword, elemParameters, pstrSessionToken, pSessionInfo, pstrSecurityToken);

If I write the code like :

String res = token_soap.logon(sessiontoken, strLogin, strPassword, elemParameters, pstrSessionToken, pSessionInfo, pstrSecurityToken);

then it show the error "Type mismatch: cannot convert from void to String". I am unable to collect the value of pstrSessionToken which it will return.

My complete code is :

public static String s_tokencall(){
                    XtkSession token = new XtkSession();
        SessionMethodsSoap token_soap = token.getSessionMethodsSoap();

        String sessiontoken ="";
        String strLogin="admin";
        String strPassword="password";
        Element elemParameters= null ;
        Holder<String> pstrSessionToken = new Holder<String>();
        Holder<Element> pSessionInfo = new Holder<Element>();
        Holder<String> pstrSecurityToken = new Holder<String>();
        String res = token_soap.logon(sessiontoken, strLogin, strPassword, elemParameters, pstrSessionToken, pSessionInfo, pstrSecurityToken);
        System.out.println(pstrSecurityToken);
        return null;}

Solution

  • It working now we need to declare the String holder with different method and the logon function will update the String variable on the call. this function will not return anything however will update the variable when executed.

    XtkSession token  = new XtkSession();
                SessionMethodsSoap token_soap = token.getSessionMethodsSoap();          
                String sessiontoken = "";
                String strLogin = "admin";
                String strPassword = "password";
                xtk.session.Element elemParameters = new xtk.session.Element();
                Holder<String> pstrSessionToken = new Holder<String>();
                Holder<xtk.session.Element> pSessionInfo = null;
                Holder<String> pstrSecurityToken = new Holder<String>();
    
                token_soap.logon(sessiontoken, strLogin, strPassword, elemParameters, pstrSessionToken, pSessionInfo, pstrSecurityToken);
    

    You will get the value in "pstrSessionToken.value"