Page 1 of 2 12 LastLast
Results 1 to 20 of 34

Thread: Consuming a web service

  1. #1
    Code400 Newbie
    Join Date
    Apr 2009
    Location
    Atlanta, GA.
    Posts
    30
    Rep Power
    434

    Consuming a web service

    I am trying to consume a web service that is provided by another department within my company. I have tried using Scott Klement's HTTPAPI utility, but I receive errors and I have no way of knowing how to deal with those (earlier attempts at outside services workd OK).

    Just wondering if anyone out there has used PHP instead of using RPG.
    Or any other methods at all?

    Thanks,
    -tdavis

  2. # 666
    Circuit advertisement
    Join Date
    Aug 1965
    Location
    Yakutsk, Russia
    Posts
    1,000,000
     

  3. #2
    Driver of cars, eater of food jamief's Avatar
    Join Date
    Jan 2004
    Location
    Belvidere, IL - United States of America
    Age
    49
    Posts
    9,416
    Rep Power
    12605

    Re: Consuming a web service

    its not PHP but....
    http://www.isockets.net/

    Some one come over here and stomp my AZZ for linking to a BOB C
    site

    Also on PHP search for CURL...
    http://curl.haxx.se/libcurl/php/examples/

    and there is even something on the iseries that pulls data..
    I posted it once, but being old I can remember...
    If you cant find it searching forums let me know and
    I will look around..

    jamie
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

  4. #3
    Analyst dhuesman's Avatar
    Join Date
    Aug 2005
    Location
    KY
    Posts
    279
    Rep Power
    1088

    Re: Consuming a web service

    have you tried debugging using httpapi? it has a simple API to turn it off and on and writes to a log file (a default log if you're ok with that).

    the largest problem I seem to recall is ensuring the webservice is called with not only a properly coded document but that the element names must match exactly ~ case matters...

    finally, there is a utility to help you thru the contruction process ~ see Klements site ~ WSDLTORPG...

  5. #4
    Harbinger of Doom tomholden's Avatar
    Join Date
    Dec 2007
    Location
    Lebanon, Tennessee, United States
    Posts
    4,326
    Rep Power
    8642

    Re: Consuming a web service

    Quote Originally Posted by jamief View Post
    its not PHP but....
    http://www.isockets.net/

    Some one come over here and stomp my AZZ for linking to a BOB C
    site

    Also on PHP search for CURL...
    http://curl.haxx.se/libcurl/php/examples/

    and there is even something on the iseries that pulls data..
    I posted it once, but being old I can remember...
    If you cant find it searching forums let me know and
    I will look around..

    jamie
    where do you live and how much is the airfare from nashville, TN???
    I'm not anti-social, I just don't like people -Tommy Holden

  6. #5
    Driver of cars, eater of food jamief's Avatar
    Join Date
    Jan 2004
    Location
    Belvidere, IL - United States of America
    Age
    49
    Posts
    9,416
    Rep Power
    12605

    Re: Consuming a web service

    Take a bus so I can get into a gym
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

  7. #6
    Lord of the Dance
    Join Date
    Aug 2008
    Location
    Memphis - Nashville TN
    Posts
    1,692
    Rep Power
    4708

    Re: Consuming a web service

    Bob Cozzi's next Tuesday tip topic is a two part series:

    1) tips on how not to get your azz kicked by promoting his site.
    2) another way to tweet from the i5

    Michael Catalani
    Manager of eCommerce Development
    Acceptance Insurance Corporation
    www.AcceptanceInsurance.com
    www.ProvatoSys.com

  8. #7
    Sr. Product Specialist FaStOnE's Avatar
    Join Date
    Nov 2005
    Location
    Phoenix, AZ
    Age
    51
    Posts
    2,611
    Rep Power
    3991

    Re: Consuming a web service

    I'd almost pay a buck to see that happen! (Tom ride a bus that is...)

    HAHAHAHAHAHAhahahahaha

    :d
    -Rick

    _____________________________

    Need a Managed File Transfer Solution -OR- iSeries Encryption?
    GoAnywhere and Crypto Complete by Linoma Software


  9. #8
    Moderator littlepd's Avatar
    Join Date
    Mar 2005
    Location
    Lewisville, TX
    Age
    50
    Posts
    1,111
    Rep Power
    3348

    Re: Consuming a web service

    WSDL2RPG was developed to ease the use of Web Services from RPG. Based on the WSDL file, published by the Web service provider, WSDL2RPG generates a Web service client module, that can be called directly the same way as any other procedure.
    "Time passes, but sometimes it beats the <crap> out of you as it goes."

  10. #9
    Code400 Newbie
    Join Date
    Apr 2009
    Location
    Atlanta, GA.
    Posts
    30
    Rep Power
    434

    Re: Consuming a web service

    I got my program using HTTPAPI to work. It seems simple enough to use, although I feel that I need to get much more familiar with web services in general as well as Scott's utility.

    I am interested in the iSockets too. I am wondering if that may be a better way to call programs from iSeries to iSeries as well (better than my current RUNRMTCMD method that is, which I understand is going away after V6.1).

    Am I making a correct statement?

  11. #10
    Harbinger of Doom tomholden's Avatar
    Join Date
    Dec 2007
    Location
    Lebanon, Tennessee, United States
    Posts
    4,326
    Rep Power
    8642

    Re: Consuming a web service

    i generally use FTP and send remote commands that way using quo rcmd
    I'm not anti-social, I just don't like people -Tommy Holden

  12. #11
    Analyst JonBoy's Avatar
    Join Date
    Jun 2005
    Location
    Mississauga, Ontario, Canada
    Posts
    392
    Rep Power
    1893

    Re: Consuming a web service

    Quote Originally Posted by tdavis View Post
    <snip>

    Just wondering if anyone out there has used PHP instead of using RPG.
    Or any other methods at all?

    Thanks,
    -tdavis
    If you want the results in an RPG program, then HTTPAPI is the way to go. Much as I like it though, PHP is _way_ easier. The following is the _entire_ code to query two web services - one to obtain a stock quote and the other to get the Cdn$ US$ exchange rate:

    PHP Code:
    <?php

    $StockQuoteClient 
    = new SoapClient("stockquote.wsdl");

    $CurrencyClient = new SoapClient(
      
    "http://www.webservicex.net/CurrencyConvertor.asmx?wsdl");

    $IBM_Price $StockQuoteClient->getQuote("ibm");
    $US_Cdn_Rate $CurrencyClient->getRate("usa""canada");
     
    print(
    "IBM stock price is \$$IBM_Price - that is \$" 
          
    . ($IBM_Price $US_Cdn_Rate) . " in Cdn\$");
    ?>

  13. #12
    Code400 Newbie
    Join Date
    Apr 2009
    Location
    Atlanta, GA.
    Posts
    30
    Rep Power
    434

    Re: Consuming a web service

    That looks pretty simple. I tried it though, and it does not work from my iSeries/IFS. I am trying to get the web service to work from both the iSeries via RPG, as well as from a PHP script. The PHP I am using generates HTTPAPI errors. The RPG version works perfectly, and they both use the same RPG program. I just wrapped the PHP into a stored procedure call.

    But it would certainly be better to call the service directly using SoapClient as you suggest. I did a little research on Coding Forums and it looks like this will be a steep learning curve for me. I know enough PHP to get by, but most of what I am seeing is definitely stuff I have not seen before. But I will try to get your example to work, or perhaps try with the email validator on webservicex also. I did get that to work also using HTTPAPI from RPG.

    Thanks!

  14. #13
    Analyst JonBoy's Avatar
    Join Date
    Jun 2005
    Location
    Mississauga, Ontario, Canada
    Posts
    392
    Rep Power
    1893

    Re: Consuming a web service

    The email validator is quite easy to use - although it took me way too long to do it for reasons that will be clear in a moment.

    The web service returns a Boolean true for a valid email and false for an invalid one ... but read on.

    Code:
        <?php
        error_reporting(E_ALL);
        $ValidateEmail = new SoapClient("http://www.webservicex.net/ValidateEmail.asmx?wsdl");
        $email = array("Email" => "me@somewhere.com");
    
        $response = $ValidateEmail->IsValidEmail($email);
        If ($response->IsValidEmailResult) {
          echo $email["Email"] . " is a valid email address";
        } else {
          echo $email["Email"] . " is not a valid email address";
        }
        ?>
    The reason it took me forever is that either there is a bug in my logic, or a bug in PHP's SOAP code. I know that because it blows up if there is an invalid email address due to a missing "@" sign in the address. Guess what I used as test data for a "bad" email address? Yup - one with no "@" sign!

    Sigh

    Jon P.

  15. #14
    Code400 Newbie
    Join Date
    Apr 2009
    Location
    Atlanta, GA.
    Posts
    30
    Rep Power
    434

    Re: Consuming a web service

    Great! That worked. Now I need to attempt to use our own webservice, which is a simple account lookup. I will find more than one value per account; for example, a primary account holder will have multiple emails addresses potentially. The tag I would be looking for is <username> (they actually use the username as the email address), so I assume that I can create a loop that would look for multiple occurrences within the response.

    Just a guess, but would that look something like this (pretending this WSDL is the correct one)?

    $GetCustomerEmails = new SoapClient("http://www.webservicex.net/ValidateEmail.asmx?wsdl");

    $response = $GetCustomerEmails->username($email);

  16. #15
    Analyst JonBoy's Avatar
    Join Date
    Jun 2005
    Location
    Mississauga, Ontario, Canada
    Posts
    392
    Rep Power
    1893

    Re: Consuming a web service

    The important thing is to take it step by step until you can understand the wsdl file and the way it is translated into PHP.

    From the example I posted:

    PHP Code:
    $email = array("Email" => "me@somewhere.com");

        
    $response $ValidateEmail->IsValidEmail($email);
        If (
    $response->IsValidEmailResult
    $email had to be an associative array so that the variable name (Email) could be associated with the value (me@some...). The name was found in the wdsl in the input parms definitions.

    You might want to check out SoapUI - a free tool that makes it easy to examine and test web services (www.soapui.org)



    Similarly the $response is an object (determined by doing a var_dump($response) ) and the name of the variable to retrieve (IsValidEmailResult) was again determined from the wsdl.

    This one took me longer to work out than usual because for most web services I find I can simply google PHP webservicvename and will find an example or two. All I could find for this ones were examples that wouldn't work!

  17. #16
    Code400 Newbie
    Join Date
    Apr 2009
    Location
    Atlanta, GA.
    Posts
    30
    Rep Power
    434

    Re: Consuming a web service

    Here is the WSDL:
    Code:
    <web:GetAllAccountInfoAcctNbr>6111027582601</web:GetAllAccountInfoAcctNbr>
    And here is the response:
    Code:
    <agentIdentities>
    <userId>agent2.geisler@dev.cox.net</userId>
    <username>agent2.geisler</username>
    </agentIdentities>
    <agentIdentities>
    <userId>agent3.geisler@dev.cox.net</userId>
    <username>agent3.geisler</username>
    </agentIdentities>
    I am trying to extract the username and userID.
    Do I need to do something like this?

    Code:
    <?php
        error_reporting(E_ALL);
        $GetUserName = new SoapClient("http://idm.east.dev.cox.net/idmwebservices/CoxIdentityServices?wsdl");
        $account = array("GetAllAccountInfoAcctNbr" => "6111027582601");
    
        $username = $GetUserName->username($account);
        $userId = $GetUserName->userId($account);
        ?>

  18. #17
    Analyst JonBoy's Avatar
    Join Date
    Jun 2005
    Location
    Mississauga, Ontario, Canada
    Posts
    392
    Rep Power
    1893

    Re: Consuming a web service

    Well you haven't actually given me the wsdl (that's the stuff in the file at http://idm.east.dev.cox.net/idmwebse...yServices?wsdl) you gave part of the request envelope but ...

    What you have look about right - I'm still fighting may way through this stuff myself.

    If I was you I would do a var_dump of the returned object and see how it is structured. Without looking it up I don't know - since agentIdentities appears to be a repeating element, it is likely that you may have to retrieve that from the returned object and _then_ access the pieces you want - a var_dump will show you what you need.

  19. #18
    Code400 Newbie
    Join Date
    Apr 2009
    Location
    Atlanta, GA.
    Posts
    30
    Rep Power
    434

    Re: Consuming a web service

    I am afraid to say that I do not know what a var_dump is.

  20. #19
    Code400 Newbie
    Join Date
    Apr 2009
    Location
    Atlanta, GA.
    Posts
    30
    Rep Power
    434

    Re: Consuming a web service

    Any idea what this means?

    Fatal error: Uncaught SoapFault exception: [Client] Function ("username") is not a valid method for this service in /www/zendcore/htdocs/cox/GetAccountInfo.php:11 Stack trace: #0 [internal function]: SoapClient->__call('username', Array) #1 /www/zendcore/htdocs/cox/GetAccountInfo.php(11): SoapClient->username(Array) #2 {main} thrown in /www/zendcore/htdocs/cox/GetAccountInfo.php on line 11

    Here is the script:

    Code:
    <?php
    
    	ini_set('display_errors','1');
    	error_reporting (E_ALL);
    
        $GetUserName = new SoapClient("http://idm.east.dev.cox.net/idmwebservices/CoxIdentityServices?wsdl");
    
        $account = array("GetAllAccountInfoAcctNbr" => "6111027582601");
    
        $username_r = $GetUserName->username($account);  <= this is line 11
        $userId_r   = $GetUserName->userId($account);
    
        echo "<br>Account: $account";
        echo "<br>User Name: $username_r";
        echo "<br>User ID: $userId_r";
    
    	var_dump($account);
    
    
     ?>

  21. #20
    Analyst JonBoy's Avatar
    Join Date
    Jun 2005
    Location
    Mississauga, Ontario, Canada
    Posts
    392
    Rep Power
    1893

    Re: Consuming a web service

    As I noted before - I think that you may need to request agentIdentities e.g. $userDetail = $GetUserName->agentIdentities($account);

    You didn't tell us what the var_dump() showed you so it is hard to be sure.

    Jon P.

  22. # 666
    Circuit advertisement
    Join Date
    Aug 1965
    Location
    Yakutsk, Russia
    Posts
    1,000,000
     

Facebook Comments


Similar Threads

  1. Web service question
    By bryanschmiedeler in forum HTTP
    Replies: 0
    Last Post: January 16th, 2009, 11:06 AM
  2. ODBC Service Program
    By jtemple in forum DB2
    Replies: 0
    Last Post: September 5th, 2007, 08:32 PM
  3. Consuming A Web Service
    By AWilson in forum ANY THING GOES
    Replies: 0
    Last Post: May 2nd, 2007, 07:54 AM
  4. Sep
    By giduturi in forum ANY THING GOES
    Replies: 3
    Last Post: January 31st, 2007, 10:10 PM
  5. Service Program
    By yogeshgupta26 in forum RPG/RPGLE
    Replies: 3
    Last Post: December 28th, 2006, 06:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •