Need help consuming webservices

Need help consuming webservices

Postby reinaldocrespo » Tue Dec 04, 2012 12:54 am

Hi. I have a need to consume webservices to send and receive information from a fwh application. I have a technical guide that includes samples using c# from the webservices provider. It is mostly consuming their webservices to send and receive files to and from their host.

Is there someone on this forum that can help? I'm willing to pay.

Please write to reinaldo-dot-crespo-at-gmail

Thank you,



Reinaldo.
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Need help consuming webservices

Postby James Bott » Sun Dec 23, 2012 7:24 am

Hi Reinaldo,

It seems I did some work on an operative report for you back in 2006. Is this related?

Either way, if you will send me more info I will take look at it to see if I might be able to help.

Happy Holidays,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Need help consuming webservices

Postby reinaldocrespo » Sun Dec 23, 2012 8:11 pm

James;

Hi. I might as well attempt to clarify what WebServices are. I may be wrong but I feel like most answers I get seem to miss the concept of consuming web services or what web services are about.

Web services are methods that execute some code on a server via xml data exchange that can also be consumed via SOAP. There are web services out there to perform many services and/or retrieve certain data from other servers. For example, there is a web service that returns any financial information of any given stock code. There is a web service to obtain a city’s information given the zip code. There are web services to manipulate data strings, such as upper(), and lower().

The web services I wish to consume accept a username and passwrd to allow sending a file and respond to that file with another file. The files I wish to upload are known as ANSI X12 format documents. I can supply a few of these documents for testing together with my user name and password for testing the web service. Producing ANSI X12 format documents to be sent to the service is not the question here. That is my expertise. I can also supply or even upload here the companion guide from the WebService creators that explains their webservices with .net sample code on how to consume these services. The webservice is developed by a clearing house named Inmediata- with whom I need to deal with.

Below is some sample code I wrote and tested to consume a freely available webservice to extract US cities information. On my sample code you will see two different methods of consuming this webservice, both function names is FetchZipFromWeb(). The first consumes the webservice using tip() harbour class and then simply trying to parse the response from the server by using harbour's Txlm() class. The second function consumes the same webservices using SOAP. Using SOAP - don't always have a positive result, so for this service I have stayed with TXML. I make extensive use of TXML() harbour class in most of my programs. I simply haven't had any success consuming the webservices in question here. If anyone on this forum has any experience using and consuming webservices, he/she might have better luck than me and I'm willing to shed some money in order to succeed consuming Inmediata's web services.

Code: Select all  Expand view

//-----------------------------------------------------------------------------------------------------
//tipclienthttp() and Turl() classes exist only after ver 1.0 in xharbour.
FUNCTION wfReadURL(cUrl)
LOCAL cPageContent:="Error: " + cUrl + " not found or timed out."
LOCAL oConn//, oUrl := TURL():New( cUrl )

    IF UPPER( LEFT( cUrl, 4 ) ) # "HTTP"
        cUrl:="http://"+cUrl
    ENDIF
 
    TRY
DEBUG "In wfReadURL", cUrl
 
        oConn := TipClientHttp():New( cUrl )

DEBUG "In wfReadURL 2"
        oConn:nConnTimeout := 20000

        IF oConn:Open()
DEBUG "In wfReadURL 3"
            cPageContent := oConn:ReadAll()
DEBUG "In wfReadURL 4"
            oConn:Close()
DEBUG "In wfReadURL 5"
        ENDIF
   
DEBUG "In wfReadURL 6"
    CATCH
       cPageContent:="Error opening " + cUrl
    END

RETURN cPageContent

//-----------------------------------------------------------------------------------------------------
FUNCTION fetchZipFromWeb( cCity, cZip )
local cUrl := "http://webservicex.net/uszip.asmx/"
local oXml, oXmlNode, cStr
local aRet := {}
local aRec := {}

    if ( cCity == Nil .or. empty( cCity ) ) .and. ;
            ( cZip == Nil .or. empty( cZip ) )
           
        Return { "No Results Found" }
       
    Endif
   
    cUrl += iif( cZip != Nil .and. !empty( cZip ), ;
                    "GetInfoByZIP?USZip=" + alltrim( cZip ),;
                    "GetInfoByCity?USCity="+ alltrim( cCity ) )
                   
    oXml := TXmlDocument():New( cStr := wfReadURL( cUrl ) )
    oXmlNode := oXml:FindFirst( "CITY" )

    While oXmlNode != Nil
       
        aRec := { oXmlNode:cData }
        oXmlNode := oXmlNode:NextInTree()
       
        While oXmlNode != Nil .and. oXmlNode:cName != "CITY"
            aadd( aRec, oXmlNode:cData )
            oXmlNode := oXmlNode:NextInTree()
        end
       
        aadd( aRet, aRec )
       
    End

Return aRet 

//-----------------------------------------------------------------------------------------------------
/*function FetchZipFromWeb( cCity, cZip )
local aRet := { "No data found" }
local oSoapClient, oResponse, oErr
local lOk := .t., oXml
local ctemp, ctemp2, ctemp3

    TRY

        oSoapClient := CreateObject( "MSSOAP.SoapClient30" )
        oSoapClient:MSSoapInit( "http://www.webservicex.net/uszip.asmx?WSDL" )

//      oSoapClient:MSSoapInit( "http://www.dataaccess.com/webservicesserver/textcasing.wso?WSDL" )
//      aRet := oSoapClient:InvertStringCase( "lower UPPER" )

    CATCH oErr

        WriteErrorLog( oErr )
        MsgStop( "Soap Client 3.0 not installed. Check Error.log for details." )
        lOk := .f.

    End

    TRY
        if lOk .and. !empty( cZip )

            oResponse = oSoapClient:GetInfoByZIP( "00950" )
            oXml := TXmlDocument():New( oResponse )
            xbrowse( oXml )
       
        Elseif lOk .and. !empty( cCity )

            oResponse = oSoapClient:GetInfoByCity( cCity )
            aRet := { "City:" + AllTrim( cCity ) + " Zip:" + oResponse:GetElementsByTagName( "ZIP" ) }

        Endif
       
    CATCH oErr
        WriteErrorLog( oErr )
    END

    DeleteObject( oSoapClient )
    DeleteObject( oResponse )          

return aRet*/

 


Reinaldo Crespo-Bazán
reinaldo dot crespo gmail.com
User avatar
reinaldocrespo
 
Posts: 972
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 83 guests