The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Calling a webservice from SLX LAN client
Posted: 13 Feb 07 6:29 AM
|
fiogf49gjkf0d Is it possible to call a webservice directly from the LAN client, or do you need a .net snapin of some sort? I am new to web services and to get my arms around a couple of things..
I am trying to call a webservice through an active form in the LAN client with xmldom using an example I found online included below. Trying to run the web service/slx/dbserver from one laptop at this point. If the service is properly run, a projectnumber should be incremented in the db - no data passed as the webservice is hitting a table with only one record. The routine seems to run without incident - I mean really without incident - no errors, no incrementing..
Am I on the right track? Any advise from the web service elders? Thanks
Code Sample (call slxweb service from vbscript with xmlDom)
Sub Button1Click(Sender)
Dim strResults, objXML, strURL, objNodes, strSQL, objNode
set objXML = CreateObject("Microsoft.XMLDOM")
objXML.async = false
strSQL="http://localhost:3224/MathService/MathService.asmx/Connecter" objXML.load(strSQL)
objNodes = objXML.xml
set objNodes = objXML.selectNodes("//NewDataSet")
For Each objNode In objNodes txtReturn.text = objNode.selectSingleNode("Connector").text ' companyName.innerText = objNode.selectSingleNode("CompanyName").text Next
set objNodes = Nothing set objXML = Nothing
End Sub |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 13 Feb 07 8:21 AM
|
fiogf49gjkf0d Yes it is possible to call a web service from the LAN Client.
I'm not sure exactly what your code is doing, but it's along the right lines.
However, is the service running on localhost? If localhost is your development box and you're running the SLX Client there it would be OK, but in production a web service would normally run on a web server accessible to everyone.
This is the sort of code I have used:
' Set up the XML strMsg = "" & _ "... some XML ...."
'-- Create XML HTTP Object Set oXML = CreateObject("Microsoft.XMLHTTP")
'-- Open the HTTP connection - False means Asynch=No Call oXML.open("POST", strURL, False)
'-- Set the Content Type Call oXML.setRequestHeader("CONTENT-TYPE", "text/xml")
'-- Send the data Call oXML.send(strMsg)
'-- Get the response sent back strXML = oXML.responseText
'-- Close the connection Set oXML = Nothing
Then load strXML into a DOM and parse it
Hope this helps?
|
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 13 Feb 07 8:39 AM
|
fiogf49gjkf0d Stuart, thanks for the sample. This is running on a single laptop right now, but will eventually live on a web server. I will be eating some training time on this project I am sure.
I guess my real disconnect is exactly what to send the WS and exactly where to send it. My web service has a method called 'Connector'. When invoked, the method selects from a one record table that holds a project number. The WS then increments the proj# and updates the proj# master table and an SLX C_Opportunity table holding the proj. number. I just want to return a message to the user that the proj. number was successfully created.
The url to the test page is http://localhost:3224/MathService/MathService.asmx?op=Connecter - Is the what I want for my strURL? This is what is returned for the record:
Your new project number is 10019
The other disconnect I have is the bit about setting up the xml to send.. I need to send the opportunityID to WS. What would this look like?
I appreciate any advice you might have - looking forward to understanding this front to back as I can see many applications for this going foward. thanks
Steve Knowles |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 13 Feb 07 9:11 AM
|
fiogf49gjkf0d Actually what I quoted there was not a good example, as that web service is an AppServer which requires XML to be passed to it and behaves in a non-standard way.
Can you use SOAP to call your web service? If you can, then the method is part of the SOAP call, something like this:
Set soapClient3 = CreateObject("MSSOAP.SoapClient30") Call soapClient3.mssoapinit("http://localhost/SOAP/Your.WSDL") strResult = soapClient3.Connecter("parameter")
Frankly, I think I'm not much help here, as all my experience of writing Web Services is in VB6 and the MS SOAP Toolkit.
|
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 13 Feb 07 9:18 AM
|
fiogf49gjkf0d Stuart you are right on. That code should work just fine without needing to do any .NET.
Of course if we are talking 7 you could just create a DLL in .NET and .Net manage it. Web Services are more tightly integrated in .NET, but the three lines of code above are pretty straight forward for VB or vbscript as we need.
Ill give it a test in the training environment today and post the results. I expect them to be "it works" |
|
|
| |
| |
| |
|
Re: Calling a webservice from SLX LAN client
Posted: 16 Feb 07 11:14 AM
|
fiogf49gjkf0d Thanks guys - much appreciated. Will I need to download the soaptoolkit to all client machines I want to access my web service using the soap method? |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 16 Feb 07 11:29 AM
|
fiogf49gjkf0d You should be able to just find the mssoap dll and install it...
Let me give this a try on a client machine really quick and get back to you..
OK Back
You need to manually install (regsvr32 or place in the PATH of the machine - system32 works) MSSOAP30.dll SOAPIS30.dll WHSC30.dll
There is another file in the same directory as these but I registered it and unregistered it and I was able to run my WS fine. The other file is named WISC30.dll and I didnt need it.
I have the same process working in .net, but it is much more code and it seems unnecessary given the ease that we accomplished the task above. I will include it in the writeup I do next week. |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 16 Feb 07 12:26 PM
|
fiogf49gjkf0d If deployment is not a good option, use the existing objects that are present with IE:
http://www.slxdeveloper.com/forum.aspx?forumid=2004&postid=5576#5576
It takes more code but if you abstract the redundant steps you will find that it is not more difficult to use than the soap client. That being said, I have never attempted to port this to vbscript. If it will not work (I would be suprised) you could always use a broswer control and javascript.
If you are going to go the route of deploying something you may opt to deploy a .Net app. Visual Studio has much better support for consuming web services than vbscript (meaning the development experience is better).
Timmus |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 21 Feb 07 9:15 AM
|
fiogf49gjkf0d Ok, I am still trying for simplicity. I created an SLX form with a button and a browser control. I am using XMLHTTP to call the web service onclick and writing the results to the HTML property of the browser control.
In the browser control I am getting the test page with the invoke button and soap request/response example that fires the method in the web service. I feel like I am very close - just need to trigger the code in the webservice to run my update statement. Am I close here? Am I calling the correct URL? This is what the web service is calling: (The method expects nothing to be passed)
Here is my client code from SLX: Sub Button1Click(Sender)
Const HOST = "http://localhost:3224/MathService/" Const URL = "MathService.asmx?op=Connecter" ' Create the HTTP object Set xmlhttp = CreateObject("Microsoft.XMLHTTP") xmlhttp.open "GET", _ HOST & URL , _ false ' Send the request synchronously xmlhttp.send "" browser1.html= xmlhttp.responseText
End Sub
Thanks |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 21 Feb 07 10:59 AM
|
fiogf49gjkf0d I have removed all error handling (most importantly I removed the check for different versions of the xml objects) and I have dumbed down my web service to accept zero parameters.
Here is some sample code that you can paste behind an active form (there is no need for a browser control):
option explicit
dim oXMLDoc dim oXMLHTTP
Sub Button1Click(Sender) set oXMLDoc = CreateObject("Msxml2.DOMDocument") set oXMLHTTP = CreateObject("Msxml2.XMLHTTP.3.0")
oXMLHTTP.onreadystatechange = getRef("HandleStateChange") call oXMLHTTP.open("POST", "http://localhost:3163/GetCurrentTime/Service.asmx/GetCurrentTime", false) call oXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") call oXMLHTTP.send()
end sub
sub HandleStateChange if (oXMLHTTP.readyState = 4) then dim szResponse: szResponse = oXMLHTTP.responseText call oXMLDoc.loadXML(szResponse) if (oXMLDoc.parseError.errorCode <> 0) then call msgbox (oXMLDoc.parseError.reason) else call msgbox (oXMLDoc.getElementsByTagName("dateTime")(0).childNodes(0).text) end if end if End Sub
To get the element names, I have found it is simplest to look at the sample result that you can see by navigating to a URL such as:
http://localhost:3163/GetCurrentTime/Service.asmx?op=GetCurrentTime
It will return something along the lines of (I replaced angled brackets with square brackets so it would post):
HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: length
[?xml version="1.0" encoding="utf-8"?] [ soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"] [soap12:Body] [GetCurrentTimeResponse xmlns="http://tempuri.org/"] [GetCurrentTimeResult]dateTime[/GetCurrentTimeResult] [/GetCurrentTimeResponse] [/soap12:Body] [/soap12:Envelope]
Note the GetCurrentTimeResult element - it returns dateTime. This is the node name we ask the XMLDom to return to us. It IS case SEnsiTivE.
I will next post an example calling a web service that requires parameters.
Hope this helps!
Timmus |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 21 Feb 07 11:12 AM
|
fiogf49gjkf0d Here is a call to a webservice that expects two numeric parameters:
option explicit
dim oXMLDoc dim oXMLHTTP
Sub Button1Click(Sender) set oXMLDoc = CreateObject("Msxml2.DOMDocument") set oXMLHTTP = CreateObject("Msxml2.XMLHTTP.3.0")
oXMLHTTP.onreadystatechange = getRef("HandleStateChange") call oXMLHTTP.open("POST", "http://localhost:3163/GetCurrentTime/Service.asmx/GetProduct", false) call oXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") call oXMLHTTP.send("Multiplicand=34&Multiplier=9")
end sub
sub HandleStateChange if (oXMLHTTP.readyState = 4) then dim szResponse: szResponse = oXMLHTTP.responseText call oXMLDoc.loadXML(szResponse) if (oXMLDoc.parseError.errorCode <> 0) then call msgbox (oXMLDoc.parseError.reason) else call msgbox (oXMLDoc.getElementsByTagName("double")(0).childNodes(0).text) end if end if End Sub
The only significant change is that you include your parameters in the Send call: call oXMLHTTP.send("Multiplicand=34&Multiplier=9"). It follows the standard name value pair convention.
Next I will try my hands at returning an object rather than simply a datetime, number, or string.
Timmus |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 21 Feb 07 11:33 AM
|
fiogf49gjkf0d Thanks Timmus! My Webservice is returning data to SLX. Thanks for dumming it down to a web service newbie level. This is great stuff.
In the example given, does the client machine need anything special to run the request? |
|
|
| |
|
Re: Calling a webservice from SLX LAN client
Posted: 21 Feb 07 11:50 AM
|
fiogf49gjkf0d Reread and I see the point, but sheesh what a bit of code for something so simple using an object created for the purpose (MSSOAP or .net) |
|
|
| |
| |
|
Re: Calling a webservice from SLX LAN client
Posted: 21 Feb 07 1:01 PM
|
fiogf49gjkf0d Your are right...
This is a problem with the creator of the WS. I always assume that the consumer of my WS is 1 of two types: 1. internal and controllable (usually me) 2. External and diverse (java, cobol.net, vbscript, ASP classic, ,net)
In case 1 you can easily deploy the complex type on both the client and server. The person object for instance would exist in both cases.
In case 2 I stick with very loosely coupled calls. Tied only to the fact that int and string etc should be availabe in the target language.
But in SLX when .net cannot be used and you must return a complex object - xmldom is the solution. Thank Timmus!
|
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 14 Jan 08 2:55 PM
|
Timmus (or anyone), I'm having some trouble with the getElementsByTagName event handler; with a Response I'm getting back from Authorize.net. Is there any information that explains that command, or something similar that I could use to simply getElements based on their position in the response file (comma separated)? I can use GetDelimitedTerm for now, but wondered if there was something outside of a SLX command. Thanks. Rob |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 14 Apr 08 2:09 PM
|
I'd like to try looking up data from web services in SLX LAN (both 7.2.2 and 6.2.6)
The Microsoft download page for the SOAP tookit (http://www.microsoft.com/downloads/details.aspx?FamilyId=C943C0DD-CEEC-4088-9753-86F052EC8450&displaylang=en) seems to say that the SOAP toolkit is depricated by .NET and that support for SOAP Toolkit ended on March 31 2008.
Does this mean that the SOAP Toolkit is not needed if .NET is installed?
Does this affect any of the help in this thread? |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 14 Apr 08 2:53 PM
|
Rob,
Samples of your code would help us narrow down the issue for you. I have written web service calls to Authorize.net from within the SalesLogix LAN client so I know it is possible. BTW - sorry I didnt catch your request back in January.
Timmus |
|
|
| |
|
Re: Calling a webservice from SLX LAN client
Posted: 14 Apr 08 3:37 PM
|
Timmus, thanks for the reply. I figured it out a while back, and it's working beautifully. The code is entirely inside of SalesLogix, and it provides real time entry into Authorize.net and feedback to the user. In less than 10 hours I was able to replace OmniRush for a client, and they were very excited about that! Writing the code probably only took an hour or so, but I had a little bit of a learning curve in working with the Authorize.net commands. Rob |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 14 Apr 08 4:59 PM
|
BTW, can someone define the word "consume" as in "consume a web service?" The word "consume" traditionally refers to use of resources that are finite or limited in some way. It makes more sense to me to "access" or "query" a web service the way one would access or query a database.
While google has lots of hits on "how to consume a web service," I haven't seen an single definition or explanation on how that would be different from querying a web service. |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 14 Apr 08 5:24 PM
|
Dan, I believe its all the same: consume, subscribe, query, call, invoke, etc. I am sure consume and subscribe came from overused analogies to describe web services.
In fact, I think "web service" is a poor choice. They are just "Web Methods", just as you tag them within .Net. Just my opinion of course .
Timmus |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 15 Apr 08 12:31 PM
|
I've gotton an external web service to work in SLX using SOAP. Now I'm trying it with XMLHTTP. I'm getting an error "Object Required:'oXMLHTTP'" error on the line if (oXMLHTTP.readyState = 4) then
Is the line set oXMLHTTP = CreateObject("Msxml2.XMLHTTP.3.0") not working? |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 15 Apr 08 12:40 PM
|
Add a stop statement at the top of your script and walk through the code. I am not sure what the problem is but you may have to invoke different versions. For example:
createobject (newest version) if err then createobject (next version) if err then createobject (oldest version) if err then tell user they are out of luck.
Make sense?
Timmus |
|
|
|
Re: Calling a webservice from SLX LAN client
Posted: 15 Apr 08 1:55 PM
|
Here's an excerpt from my code:
set oXMLDoc = CreateObject("Msxml2.DOMDocument") set oXMLHTTP = CreateObject("Msxml2.XMLHTTP.3.0") msgbox"Ready state is " & oXMLHTTP.readyState oXMLHTTP.onreadystatechange = getRef("HandleStateChange")
And later on....
sub HandleStateChange dim szResponse msgbox"State has changed. Ready state is " & oXMLHTTP.readyState if oXMLHTTP.readyState = 4 then ....
The first messagebox says "Ready State is 0" The second bombs out with "Object Required: oXMLHTTP" It's as if the Object isn't accessable once we move to the sub
|
|
|
|