how to call web service functions - web-services

Nowadays, we see that some APIs are provided as web services. For example, ONVIF provides APIs in wsdl and xsd files from which gsoap generates sources. My question is that regardless of the context for which the API is generated, can we rely only on the wsdl and xsd files or we need some additional documents to know how to call and use these generated classes, functions and in the whole these generated cpp codes? In another words, can the xml files suffice for extracting the information of how to call the generated codes and use them?
If just having the wsdl and xsd files are enough, please tell me how to extract these information.

No, with the wsdl files, you can only create the classes and methods.
Normaly the names are the same as the element names in the soap request.
So you can look there how and witch method you have to use.
The xsd file is only to verify the request, if they are in a valid format.
A documentation would be helpfull. Without one, you have to try and error.

Related

ONVIF: Which wsdl files are needed for Profile S

I am trying to write an ONVIF client in C++ using gsoap. The executable wsdl2h will generate the needed header and the rest I think I understand.
My question:
Which wsdl files will I need, if I want my client to work with a device that supports ONVIF Profile S (let's say the mandatory specs)? Most importantly, how do I find that out? Is there a one-to-one link? Also, because I am behind a proxy and I can't seem to get that to work, can I somehow download all the needed wsdl files in a bunch?
Here's a list of .wsdl files I found...
https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl
https://www.onvif.org/ver10/events/wsdl/event.wsdl
https://www.onvif.org/ver10/media/wsdl/media.wsdl
https://www.onvif.org/ver20/media/wsdl/media.wsdl
https://www.onvif.org/ver10/recording.wsdl
https://www.onvif.org/ver10/display.wsdl
https://www.onvif.org/ver10/receiver.wsdl
https://www.onvif.org/ver10/deviceio.wsdl
https://onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl
https://www.onvif.org/onvif/ver10/search.wsdl
https://www.onvif.org/ver10/replay.wsdl
https://www.onvif.org/ver10/advancedsecurity/wsdl/advancedsecurity.wsdl
https://www.onvif.org/ver20/imaging/wsdl/imaging.wsdl
https://www.onvif.org/ver10/analyticsdevice.wsdl
https://www.onvif.org/ver10/thermal/wsdl/thermal.wsdl
Hope this helps!
There is not a WSDLfile that automatically includes all the WSDL files you may need.
If you check the ONVIF Profile S page, you will find the Profile S specification. As you can see from the PDF, there are some functions that are mandatory for a client to be conformant, others are conditional mandatory (you have to implement them if you want to claim support for those features) and some are optional.
After you choese what you want to support, you need to include the WSDL files for the services that you must implement.

How to serialize a XML file to Thrift file ? (to put in HDFS)

Since many days, I inquire a lot of informations about Big Data and especially about Thrift and HDFS/Hadoop.
I have many many XML files which I want to store in a HDFS file system. (and after, make statistics etc... from the data of these files)
So I would like to serialize my XML files with Thrift. (to validate the structure and to make durable ..)
Then, stock them in HDFS.
Is it possible ? ( XML => Thrift => HDFS ) without use RPC service.
To do the test, I would like to use a linux VM (for HDFS) and PHP language (for thrift).
Thank you.
You can use the serialization part without the RPC part, yes. Look for "serializer" in the Thrift source tree, you should find some examples. If not for PHP, then for sure for some other languages.
You have to do a little work on your own, because there is not such a thing a "the" way to convert XML into Thrift structures. The steps are - roughly - as follows
define the data structures to hold the XML data as Thrift IDL constructs
generate the desired code using the Thrift Compiler
add the serializer code as needed
put together some code that
reads each XML file
builds the Thrift structures from it
serializes the data and puts them into HDFS
Depending on the layout of your XML data and on the number of XML structures used, this may need some effort. It could be an idea to generate at least the IDL file programmatically by some other tool, maybe even some of the other code needed. Thrift cannot support you with this, although it could be an option - again, depending on your current situation, language and tools available.

Are there tools for generating the clients model from an odata metadata?

Back in the good old days of flex (anyone?) flash builder provided a tool for generating the clients model based on the server model. Is there something similar for generating, say an ember's app model, based on the odata metadata?
datajs documentation does mention the subject. Though the reference for OData.read used in the sample doesn't say explicitly that it interprets the metadata somehow, it seems implied. You'll have to verify that.
It does take an optional metadata object however, suggesting there exists a formal representation for metadata to the library -- I would imagine generated via OData.read. Documentation seems non-existent. I don't know what that looks like.
From there, you should be able to further transform the model to something suitable for Ember.
(datajs is a low-level javascript library that implements client-side OData operations.)
I also know that JayStack provides a JaySvcUtil, a CLI process assembly (.NET program) that extracts metadata. The destination format is JavaScript code, though the model it uses is specific to JayData. Still, you may be able to work from there.
As mentioned by Maya, Microsoft provides the OData Client Code Generator, which generates .NET proxies. Might be more difficult to transform that.
If none of these work for you (which is actually likely), you can always parse the $metadata resource yourself -- I believe it always uses an XML representation in all current versions of OData.
If you need to do it dynamically in the browser, use DOMParser or XMLHttpRequest. More information.
If you can do it statically, then by all means do so -- it's simply best for performance. In this case, you can use whatever language and runtime tools you want to fetch, parse, transform and re-serialize the model.
The format (CSDL) is specified for OData here (v4) and here (v3).
Finally, check out this list, something new may appear that better fits your needs.
There are two suggestion which may help you.
1, OData provide client code generator to generate client-side proxy class. Just need to pass metadata url, .net client code will be generate for you. You can follow the following blog:
http://blogs.msdn.com/b/odatateam/archive/2014/03/11/how-to-use-odata-client-code-generator-to-generate-client-side-proxy-class.aspx
2, If the model means "EdmModel", you can just de-serialize $metadata. OData reader can de-serialize the $metadata to IEdmModel, which can be used in client side. The following is sample code:
HttpWebRequestMessage message = new HttpWebRequestMessage(new Uri(ServiceBaseUri.AbsoluteUri + "$metadata", UriKind.Absolute));
message.SetHeader("Accept", MimeTypes.ApplicationXml);
using (var messageReader = new ODataMessageReader(message.GetResponse()))
{
Model = messageReader.ReadMetadataDocument();
}

WSDL possible to transfer a FILE type?

A "checkResult" service deployed on a node machine is defined to return the result on the node to a cluster controller that sends the request.The result on node ,which is in the form of file, may vary drastically in length,as is often the case with daily log files.
At first,i thought it might be ok just using a single string to pack the whole content of the file,so i defined
checkResult(inType *in,OutType *out)
where the OutType* is char*. Then i realized that the string could be in KB length or even more. So i wonder whether it is proper to use string here.
I googled a lot and could not find the max length permitted in wsdl(maybe conflict with the local maxbuffer length as well) and did not find any information about transferring a file type parameter either.
Using struct type may be suggested ,but it could be so nested for the file and difficult to parse when some of the elements inside could be nil and absent.
What'd you do when you need to return a file type result or large amount of data in a webservice?
p.s the server and client both in C.
When transferring a large amount of data in a (SOAP) web service request or response, it is generally better practice to use an attachment mechanism versus including the data as part of the body. Probably the order for considering attachment mechanism (broadest to narrowest adoption):
Message Transmission Optimization Mechanism (MTOM) - The newest of these specifications (http://www.w3.org/TR/soap12-mtom/) which is supported in many of the mainstream languages.
SOAP with Attachments - This specification (http://www.w3.org/TR/SOAP-attachments) has been around for many years and is supported in several languages but notably not by Microsoft.
Direct Internet Message Encapsulation (DIME) - This specification (http://bgp.potaroo.net/ietf/all-ids/draft-nielsen-dime-02.txt) was pushed by Microsoft and support has been provided in multiple languages/frameworks including java and .NET.
Ideally, you would be able to work with a framework to give you code stub generation directly from a WSDL indicating MTOM-based web service.
The critical parts of such a WSDL document include:
MTOM policy declaration
Policy application in the binding
Placeholder for the reference to the attachment in the types (schema) section
If you are working contract-first and have a WSDL in hand, the example in section 1.2 of this site (http://www.w3.org/Submission/WS-MTOMPolicy/) shows the simple additions to be made to declare and apply the MTOM policy. Appendix I of the same site shows an example of a schema element which allows a web service client or server to identify a reference to the MTOM attachment.
I have not implemented a web service or client in C, but a brief scan of recently-updated packages revealed gSoap (http://www.cs.fsu.edu/~engelen/soap.html) as a possibility for helping in your endeavors.
Give those documents a look and see if they help to advance your project.

c++ linux library for creating an xml and reading from an xml (serialize/ deserialize)

I am working in Ubuntu. I have a .h file with a class and a lot of nested classes. I would like to create an XML file from an object. Can someone please give me a library that creates XML files, serializes, and deserializes objects? I am compiling with g++.
Try libxml2.
But it seems like you want to serialize and desirialize an object from and to XML. Boost::serialization might come in handy. it also supports serialization from and to XML.
Here you can find an example for Boost::serialization with XML.
If you want to handle XML in C++ you may have a look at these projects
http://xmlsoft.org/
http://www.grinninglizard.com/tinyxml/
http://xerces.apache.org/xerces-c/
It doesn't serialize with XML (which I consider a feature, personally), but Google protocol buffers does a good job of serializing (in a binary format) objects that are defined in the .proto language.
You may want to explore the XML Data Binding. The main idea is that given an xml schema the data binding software generates a class hierarchy corresponding to the schema, and the code to serialize / unserialize (called marshal / unmarshal). There are several tools that can do this, gsoap is a free one, xmlSpy is one of the commercial ones.
What you describe is an XML data binding for C++. There are several tools for what you want to do, see e.g. XML Data Binding Tools. I've used gSOAP for several C++ projects, including starting from C++ files with classes which is really nice (other tools force you to start from XML schemas or WSDLs). With gSOAP I have been able to generate XML schemas and XML, see e.g. map C/C++ types to XML schema.
A super-lightweight, simple xml library is pugixml.
Though keep in mind that C++ does not have the reflection capabilities that .NET has. No library will generate the serialization/deserialization code for you (which I guess you hoped for).