Monday, March 26, 2012

Call webservices that expect bytes array

Do I need to write a custom converter to be able to call a webservice that has a byte[] argument?

What javascript types should I pass in to pass into the remote call?


Thanks,
Julien

Julien:

The closest type contained in JavaScript to a byte[] array would be the string, represented as an array of characters without encoding.

To the best of my knowledge, the only way to pass a undetermined amount of data to a web service using JavaScript would be to use the HTTP POST protocol.

A code snippet:

<html>
<head>
<title>Sample JavaScript Web Service with Byte Array</title>
<script type="text/javascript" language="javascript">
function load()
{
var form = document.createElement("form");
form.action = "http://www.samplesite.com/services/sampleservice.asmx/function";
form.encoding = "multipart/form-data";
form.method = "post";

var textbox = document.createElement("input");

form.appendChild(textbox);

var button = document.createElement("input");
button.type = "submit";
button.value = "Send to WS";

form.appendChild(button);

document.getElementById("container").appendChild(form);
}
</script>
</head>
<body onLoad="load()">
<div id="container"></div>
</body>
</html
That should do it! It does not take advantage of any of the Atlas Framework, but it would work the same from within an synced object initialization.

Good Luck!

Deavon McCaffery
JavaScript does not handle binary arrays. What is your scenario and what do you want to do with the binary data on the client?

No comments:

Post a Comment