XMLRPC with dynamic server name

I have everything working great with my PHP Web Service. However, the client now wants to be able to select a server at runtime. I figured this was no problem and created a user defaults entry for this.

Here’s the problem, I can’t figure out how to use a variable name in the “tell application” command. For example, my code used to be:


tell application "http://www.myserver.com/ws_admin.php"
set returnValue to call xmlrpc {method name:"admin.checkLogin", parameters:{strUser, strPass}}
end tell

but now I want it to do something like this


set strServer to "[url=http://www.myserver.com]www.myserver.com[/url]"
tell application "http://" & strServer & "/ws_admin.php"
 --code
end tell

This does not work. Can anyone explain what I need to do? I’m pretty new to AS so go easy on me :slight_smile:

With the variable app name, AppleScript doesn’t know how to check the syntax to make sure the app can handle the commands your asking it to handle. The solution is to wrap the variable tell block in a “using terms from” block for an app that has the same command set:

This allows AppleScript to use the dictionary from the known app to check the syntax and still tell the variable app to handle the command.

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Thanks for the tip. Just out of curiosity, does this mean that AS actually verifies it’s a legitimate XML RPC web service when building, or does the application string just have to be a valid URL?

I’m curious because the myserver.com example my not be around forever, and I’d hate to bind code to a server that will disappear in the future.

Well, I tried implementing your code and while it allowed the project to build and run, it still does not work. I get an error like this:

testserver.com” doesn’t understand the «event rpc RPC2» message. (-1708)

Of course, I pulled out my real server name, but that’s the error. Here’s the code that generates it.


set strRPCServer to "myserver.com/demo"
		using terms from application "http://myserver.com/demo/ws_admin.php"
			tell "http://" & strRPCServer & "/ws_admin.php"
				set returnValue to call xmlrpc {method name:"admin.checkLogin", parameters:{strUser, strPass}}
			end tell
		end using terms from

Any ideas why this isn’t working? If I remove the variable and type in a string with the server name it works fine.

Thanks.

Oops, figured it out. Turns out I’m missing “application” in that tell statement. Must have deleted it accidentally. Also by running tests, I verified that it’s only looking for a valid URL format in the “using terms from” statement, not binding to the actual server.

Thanks again for all your help. Hopefully some day I’ll know enough to help someone else out on this forum. :smiley:

Hi,

When using variable in the tell statement, use:

using terms from application “http://www.apple.com/placebo

for http url.

gl,