ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Consuming a web service

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Re: Consuming a web service

    its not PHP but....


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

    Also on PHP search for CURL...


    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

    Comment


    • #3
      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...

      Comment


      • #4
        Re: Consuming a web service

        Originally posted by jamief View Post
        its not PHP but....


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

        Also on PHP search for CURL...


        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

        Comment


        • #5
          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

          Comment


          • #6
            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
            IS Director, eCommerce & Web Development
            Acceptance Insurance Corporation
            www.AcceptanceInsurance.com
            www.ProvatoSys.com

            Comment


            • #7
              Re: Consuming a web service

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

              HAHAHAHAHAHAhahahahaha

              :d

              Comment


              • #8
                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."

                Comment


                • #9
                  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?

                  Comment


                  • #10
                    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

                    Comment


                    • #11
                      Re: Consuming a web service

                      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\$");
                      ?>

                      Comment


                      • #12
                        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!

                        Comment


                        • #13
                          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.

                          Comment


                          • #14
                            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);

                            Comment


                            • #15
                              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!

                              Comment

                              Working...
                              X