I am trying to sent a byte array from my Blackberry application to a .NET webservice (asmx).
I am using the Sun Java Wireless Toolkit (WTK) 2.5.2 to generate the webservice stubs to use within the Blackberry solution. The WTK project settings are producing the stubs using the JSR 172 specification.
I have created the Webservice using .NET 2005, using the following method:
[WebMethod]
public string UploadImage(byte[] Data, string Name)
{
//do stuff
}
I generate the stubs from the WSDL of this webservice but I am receiving: "error: Found unknown simple type: byte[]". I've used this method of generating stubs and I've not received any errors before, granted all input variables have been simple types but I've used this to return arrays of custom objects. When I check the WSDL file the type is base64Binary.
Is there something I can use other than the byte array to pass the data in? Or is there some sort of setting that I am missing to allow the webservice to take it a byte array?
The best thing to do is probably just specify the parameter as a String. Base64 is ASCII representation of binary data.
you have the declare your method with String instead of byte[].
Than you can use the following snippet on the client side:
byte[] chunk = ...;
String data= Base64OutputStream.encodeAsString(chunk, 0, chunk.length, false, false);
UploadImage(data, name)
and on the server side you can use:
byte[] byteArray;
byteArray = Base64.decode(data);
Related
I am trying to understand how to send SOAP requests with JSON formatted data to docusign. Following this guide is only for pdfs:
https://developers.docusign.com/docs/esign-soap-api/how-to/request-signature/
I created a template on docusign developer and downloaded it, which is in json format.
How do I send the data in that format? Is it currently stored as documentBase64, do I need to convert it the data to a PDF, or just set the documents bytes to that value (doc.PDFBytes)? Attempting to do the ladder, gives me a soap error:
Soap Fault: The validation of the PDF file failed.
What fields are required to pull out of the json at minimum?
Yes, I have the envelope, recipient and tabs set up. I currently am able to send PDFs as is to get signed, just not json formatted data.
Here is an example of attempting to pull out the documentbase64 data and set it to the pdfbytes field:
string pdfbytes = json4.value("documentBase64", "oops");
doc->PDFBytes = new xsd__base64Binary();
size_t pdfSize = 0;
// Double conversion to get it to match the datatype for *PDFBytes->ptr*
const unsigned char* t = reinterpret_cast<const unsigned char *>( pdfbytes.c_str() );
unsigned char* y = const_cast<unsigned char*>(t);
doc->PDFBytes->__ptr = y;
doc->PDFBytes->__size = pdfbytes.size();
UPDATE:
Solved my own problem. You will need to decode your base64 data from docusign. I used the following decoder:
https://renenyffenegger.ch/notes/development/Base64/Encoding-and-decoding-base-64-with-cpp/
Updated code:
string pdfbytes = json4.value("documentBase64", "oops");
std::string decoded = base64_decode(pdfbytes);
Unless you have a really good reason, I highly recommend you consider using the DocuSign eSignature REST API and not the DocuSign eSignature SOAP API.
Not every feature is supported by the SOAP API.
You could use https://github.com/jgaa/restc-cpp to make REST API calls from a C++ codebase.
Also, remember that documents sent in the API has to be base64 encoded. This goes for both REST and SOAP.
I hope I don't have misunderstood the Thrift concept, but what I see from (example) questions like this, this framework is composed by different modular layers that can be enabled or disabled.
I'm mostly interesed in the "IDL part" of Thrift, so that I can create a common interface between my C++ code and an external Javascript application. I would like to call C++ functions using JS, with Binary data transmission, and I've already used the compiler for this.
But both my C++ (the server) and JS (client) application already exchange data using a C++ Webserver with Websockets support, it is not provided by Thrift.
So I was thinking to setup the following items:
In JS (already done):
TWebSocketTransport to send data to my "Websocket server" (with host ws://xxx.xxx.xxx.xxx)
TBinaryProtocol to encapsulate the data (using this JS implementation)
The compiled Thrift JS library with the correspondent C++ functions to call (done with the JS compiler)
In C++ (partial):
TBinaryProtocol to encode/decode the data
A TProcessor with handler to get the data from the client and process it
For now, the client is already able to sent requests to my websocket server, I see receiving them in binary form and I just need Thrift to:
Decode the input
Call the appropriate C++ function
Encode the output
My webserver will send the response to the client. So no "Thrift server" is needed here. I see there is the TProcessor->process() function, I'm trying to use it when I receive the binary data but it needs an in/out TProtocol. No problem here... but in order to create the TBinaryProtocol I also need a TTransport! If no Thrift server is expected... what Transport should I use?
I tried to set TTransport to NULL in TBinaryProtocol constructor, but once I use it it gives nullptr exception.
Code is something like:
Init:
boost::shared_ptr<MySDKServiceHandler> handler(new MySDKServiceHandler());
thriftCommandProcessor = boost::shared_ptr<TProcessor>(new MySDKServiceProcessor(handler));
thriftInputProtocol = boost::shared_ptr<TBinaryProtocol>(new TBinaryProtocol(TTransport???));
thriftOutputProtocol = boost::shared_ptr<TBinaryProtocol>(new TBinaryProtocol(TTransport???));
When data arrives:
this->thriftInputProtocol->writeBinary(input); // exception here
this->thriftCommandProcessor->process(this->thriftInputProtocol, this->thriftOutputProtocol, NULL);
this->thriftOutputProtocol->readBinary(output);
I've managed to do it using the following components:
// create the Processor using my compiled Thrift class (from IDL)
boost::shared_ptr<MySDKServiceHandler> handler(new MySDKServiceHandler());
thriftCommandProcessor = boost::shared_ptr<TProcessor>(new ThriftSDKServiceProcessor(handler));
// Transport is needed, I use the TMemoryBuffer so everything is kept in local memory
boost::shared_ptr<TTransport> transport(new apache::thrift::transport::TMemoryBuffer());
// my client/server data is based on binary protocol. I pass the transport to it
thriftProtocol = boost::shared_ptr<TProtocol>(new TBinaryProtocol(transport, 0, 0, false, false));
/* .... when the message arrives through my webserver */
void parseMessage(const byte* input, const int input_size, byte*& output, int& output_size)
{
// get the transports to write and read Thrift data
boost::shared_ptr<TTransport> iTr = this->thriftProtocol->getInputTransport();
boost::shared_ptr<TTransport> oTr = this->thriftProtocol->getOutputTransport();
// "transmit" my data to Thrift
iTr->write(input, input_size);
iTr->flush();
// make the Thrift work using the Processor
this->thriftCommandProcessor->process(this->thriftProtocol, NULL);
// the output transport (oTr) contains the called procedure result
output = new byte[MAX_SDK_WS_REPLYSIZE];
output_size = oTr->read(output, MAX_SDK_WS_REPLYSIZE);
}
My webserver will send the response to the client. So no "Thrift server" is needed here. I see there is the TProcessor->process() function, I'm trying to use it when I receive the binary data but it needs an in/out TProtocol. No problem here... but in order to create the TBinaryProtocol I also need a TTransport! If no Thrift server is expected... what Transport should I use?
The usual pattern is to store the bits somewhere and use that buffer or data stream as the input, same for the output. For certain languages there is a TStreamTransport available, for C++ the TBufferBase class looks promising to me.
I'm trying to send a large (~3 MB array of vector data from my native c++ host to its embedded dart VM using the async (Send/ReceivePort) pattern described in https://www.dartlang.org/articles/native-extensions-for-standalone-dart-vm/
My goal is to transfer a native c++ vector of Float32x4 to a typed dart Float32x4List object in one go.
All is well and jolly when I try and send integer arrays, and i was able to run the example in the tutorial, but when i try to construct a native Dart_CObject as in:
Dart_CObject obj;
obj.type = Dart_CObject_kTypedData;
obj.value.as_typed_data.type = Dart_TypedData_kFloat32x4;
obj.value.as_typed_data.values = &myData;
obj.value.as_typed_data.length = myDataLength;
Dart_PostCObject(reply_port_id, &obj);
I get:
vm/dart_api_message.cc:1105: error: unimplemented code
Since it seems that currently only Dart_TypedData_kUInt8 and Dart_TypedData_kInt8 appear to be ready for serialisation.
Is there a work-around for this? i.e. is there a way to push my native data to the dart VM as a uint8 blob and re-interpreting that buffer in dart as a Float32x4List?
You can send the data to Dart as an Uint8List and use the Float32x4List.view constructor to re-interpret the data as an Float32x4List. E.g.
Uint8List data = ...
Float32x4List view = new Float32x4List.view(data.buffer)
...
I need to create a simple web service (being the "server"). The goal is to provide some data I do read in an Qt / C++ application as JSON data. Basically a JavaScript application in the browser shall read its data from the Qt app. It is usually a single user scenario, so the user runs a Google Maps application in her browser, while additional data come from the Qt application.
So far I have found these libs:
Qxt: http://libqxt.bitbucket.org/doc/0.6/index.html but being a newbie on C++/Qt I miss some examples. Added: I have found one example here
gSoap: http://www.cs.fsu.edu/~engelen/soap.html has more examples and documentation and also seems to support JSON
KD SOAP: http://www.kdab.com/kdab-products/kd-soap/ with no example as far as I can tell, docu is here
Qt features itself, but it is more about acting as a client: http://qt-project.org/videos/watch/qt-networking-web-services
Checking SO gives me basically links to the above libs
webservice with Qt with an example I do not really get.
How to Create a webservice by Qt
So basically I do have the following questions:
Which lib would you use? I want to keep it as simple as possible and would need an example.
Is there another (easy!) way to provide the JSON data to the JavaScript Web page besides the WebService?
-- Edit, remarks: ---
Needs to be application intrinsic. No web server can be installed, no extra run time can be used. The user just runs the app. Maybe the Qt WebKit could be an approach....
-- Edit 2 --
Currently checking the tiny web servers as of SO " Qt HTTP Server? "
As of my tests, currently I am using QtWebApp: http://stefanfrings.de/qtwebapp/index-en.html This is one of the answers of Edit 2 ( Qt HTTP Server? )
Stefan's small WebServer has some well documented code, is written in "Qt C++" and easy to use, especially if you have worked with servlets already. Since it can be easily integrated in my Qt project, I'll end up with an internal WebServer.
Some demo code from my JSON tests, showing that generating the JSON content is basically creating a QString.
void WebServiceController::service(HttpRequest& request, HttpResponse& response) {
// set some headers
response.setHeader("Content-Type", "application/json; charset=ISO-8859-1");
response.setCookie(HttpCookie("wsTest","CreateDummyPerson",600));
QString dp = WebServiceController::getDummyPerson();
QByteArray ba = dp.toLocal8Bit();
const char *baChar = ba.data();
response.write(ba);
}
If someone has easy examples with other libs to share, please let me know.
QByteArray ba = dp.toLocal8Bit();
const char *baChar = ba.data();
You don't need to convert the QByteArray to char array. Response.write() can also be called with a QByteArray.
By the way: qPrintable(dp) is a shortcut to convert from QString to char array.
We need to compress (or rather uncompress) some data we send to a pda client using a webservice.
Below I have a simple concept that will work if consumed by a regular .net app.
Unfortuantly, as the compact framework doesn't have the IO.Compression classes we can't see how this is possible without writing our own compression algorithms (as you'd don't have the ability to uncompress at the pda client end).
We have to use .net 2 only.
Dim c As New TestClass
c.Prop1 = "Test"
c.Prop2 = 1234
Dim XmlMemStream As New IO.MemoryStream
Dim mySerilizedObj As Xml.Serialization.XmlSerializer = New Xml.Serialization.XmlSerializer(GetType(TestClass))
mySerilizedObj.Serialize(XmlMemStream, c)
Dim gz As New IO.Compression.GZipStream(XmlMemStream, IO.Compression.CompressionMode.Compress, False)
This needs to be done at application level and not Server Level (HTTP compression).
Thanks
You could try using SharpZipLib on the client, I have used it successfully on Compact Framework.