How to call C# Web Service in Corona (Lua)? - lua

I am trying to call a web service written in C#. Below is client side in corona:
local client = require "soap.client"
local ns, meth, ent = client.call {
url = "http://172.16.1.162:7878/BaksetBilgi.svc",
soapaction = "doubler",
method = "http://titck.kara.com/bask",
entries = {
......}
When I run this code, it gives error :
module 'soap.client' not found:resource (soap.client.lu) does not exist in archive..
How can I solve it?

That module is not part of corona. Looks like it's only 3 files, you could copy them into your Corona project. Note that the language that SOAP service is written in is irrelevant to the client: SOAP is a protocall, if you know how to format your data in HTML then you can do SOAP. Look at any good SOAP tutorial. But I don't know why you wouldn't want to use that library, just copy the files into your project.

Related

Lua - Download via http and https (Lua 5.1 embedded)

I’m sure this is not a unique question about Lua 5.1 (especially an embedded instance, where you can’t install modules, your only options is pure Lua files/reference, therefore I can’t install something like luacurl ). I’ve seen this matter referred to in various SO places, and tried them, but I can’t seem to find a fix to make an https file download request work in this particular Lua environment..
To give you an example, the code below aims to download 2 different files, the http call works fine, returning a 200 code, but the https one doesn’t, it doesn’t return anything ?
Both targets can be access directly via the browser..
Please could some highlight what I’m missing in the https call to make it work?
print("--------DOWNLOAD http---------")
local http = require("socket.http")
local body, code = http.request("http://pbs.twimg.com/media/CCROQ8vUEAEgFke.jpg")
print(code)
if not body then error(code) end
local f = assert(io.open('mnt/nas/webtest1.jpg', 'wb')) -- open in "binary" mode
f:write(body)
f:close()
print("--------DOWNLOAD https---------")
local https = require "ssl.https" --luasec
local body, code = https.request("https://u.cubeupload.com/jbcooper/16146313918060.jpg")
print(code)
if not body then error(code) end
local f = assert(io.open('mnt/nas/webtest2.jpg', 'wb')) -- open in "binary" mode
f:write(body)
f:close()
As requested, the following returns nothing at all..
local https = require "ssl.https" --luasec
print(https.request("https://u.cubeupload.com/jbcooper/16146313918060.jpg"))
If it helps, if I run the following it returns 0.4
local https = require("ssl.https")
local httpsVersion = string.sub(https._VERSION,1,3)
print (httpsVersion)

Share JavaScript code between Twilio functions

I have a Twilio serverless app that contains several functions. Several of the functions have code that is similar that I have extracted out into a separate file that can be used by the loaded and used by the functions.
This works if I run things locally with twilio serverless:start, but fails when I deploy to Twilio and try using the endpoints from their. On Twilio the functions fail with the message Cannot find module '<path to module>' \nRequire stack ...
functions (two files like this):
const share = require('shared-code');
shared-code.js:
exports.helperFn = function() {}
How can I easily share JavaScript code between Twilio functions?
Twilio developer evangelist here.
You can find the path of a Function here. Then use that path in the file in which you want to reference code from another file:
let path = Runtime.getFunctions()['function-path'].path; //example: Runtime.getFunctions()['api/identity'].path;
where the Function path is the Function name after the / in the URL.
Then to use that code from a Function in a different Function, you could require this
let module = require(path);
Let me know if this helps at all!

downloading and storing files from given url to given path in lua

I'm new with lua but working on an application that works on specific files with given path. Now, I want to work on files that I download. Is there any lua libraries or line of codes that I can use for downloading and storing it on my computer ?
You can use the LuaSocket library and its http.request function to download using HTTP from an URL.
The function has two flavors:
Simple call: http.request('http://stackoverflow.com')
Advanced call: http.request { url = 'http://stackoverflow.com', ... }
The simple call returns 4 values - the entire content of the URL in a string, HTTP response code, headers and response line. You can then save the content to a file using the io library.
The advanced call allows you to set several parameters like HTTP method and headers. An important parameter is sink. It represents a LTN12-style sink. For storing to file, you can use sink.file:
local file = ltn12.sink.file(io.open('stackoverflow', 'w'))
http.request {
url = 'http://stackoverflow.com',
sink = file,
}

how to upload files to rackspace cloud using windows services

using my windows service (target framework=.Net framework 4.0 client profile) I am trying to upload files to rackspace cloudfiles.
I found out some asp.net c# apis here https://github.com/rackspace/csharp-cloudfiles
but looks like they are not compatible with windows services.
any clues how to make this work together?
It's perfect library for work with rackspce. I am use it. And i am sure that it's not problem to use this library inside of windows service. But i think possible problems with .net framework client profile and com.mosso.cloudfiles.dll. But try first with client profile.
Also i use following code to upload files to Rackspace(Configuration it's my configuration class. Instead of 'Configuration.RackSpaceUserName' and 'Configuration.RackSpaceKey' use yous own creadentials):
private Connection CreateConnection()
{
var userCredentials = new UserCredentials(Configuration.RackSpaceUserName, Configuration.RackSpaceKey);
return new Connection(userCredentials);
}
public void SaveUniqueFile(string containerName, string fileName, Guid guid, byte[] buffer)
{
string extension = Path.GetExtension(fileName);
Connection connection = CreateConnection();
MemoryStream stream = new MemoryStream(buffer);
string uniqueFileName = String.Format("{0}{1}", guid, extension);
connection.PutStorageItem(containerName, stream, uniqueFileName);
}
Configuration something like this:
public class Configuration
{
public static string RackSpaceUserName = "userName";
public static string RackSpaceKey= "rackspaceKey";
}
I you don't want to use com.mosso.cloudfiles.dll very easy create you own driver for rackspace. Because actually for upload file to rackspace you just need send put request with 'X-Auth-Token' header. Also you can check request structure using plugin for firefox to view and upload files to Rackspace and firebug.
I have some example in C# using that same library here :
https://github.com/chmouel/upload-to-cf-cs
this is a pretty simple CLI but hopefully that should give an idea how to use it.
I've been around this for about one hour and weird things are happening into VS2010. Although I have referenced the dll and intellisense is working, cannot compile.
It looks like the referenced dll disappears. So, my recomendation in case you go into the same issue, use rack space for .NET 3.5: csharp-cloudfiles-DOTNETv3.5-bin-2.0.0.0.zip
Just be sure to change your project to the same framework version. It works really good.
For your reference, the downloads page is here: https://github.com/rackspace/csharp-cloudfiles/downloads

Load or Stress Testing Tool with URL Import Functionality

Can someone recommend a load testing tool which allows you to either:
a. replay an IIS (7) log(s) to simulate a real live site daily run;
b. import a CSV or equivalent list of URLS so we can achieve a similar thing as above but at a URL level;
c. .net API so I can create simple tests easily from my list of URLS is also a good way to go.
I do not really want to record my tests.
I think I can do B) with WAPT but need to create an XML file manually, not too much grief, but wondering if any tools cover these scenarios out the box.
Visual Studio Test Edition would require some code to parse the file into a suitable test run.
It is a great load testing solution.
Our load testing service lets you write a very simple script using JavaScript to pull data out of a CSV file and then fetch those URLs. For example, the following code would pluck 10 random URLs from the CSV file and fetch them as part of a single session:
var c = browserMob.openHttpClient();
var csv = browserMob.getCSV("urls.csv");
browserMob.beginTransaction();
for (var i = 0; i < 10; i++) {
browserMob.beginStep("Step 1");
var url = csv.random().get("url");
c.get(url);
browserMob.endStep();
}
browserMob.endTransaction();
The CSV file itself needs to be a normal CSV file with the first row containing a header named "url". This script would be run repeatedly for each virtual user participating in a load test.
We have support for so called 'uri-format' in our open-source tool called Yandex.Tank You simply put all your uris to a file, one uri -- one line, then specify headers in your load.ini like this:
[phantom]
address=example.org
rps_schedule=line(1, 1600, 2m)
headers = [Host: mts-maps.yandex.ru]
[Connection: close] [Bloody: yes]
ammo_file = ammo.uri
ammo.uri:
/
/index.html
/1/example.html
/2/example.html

Resources