Calling c++ in web-services - c++

In my mind a webservice is a service that create a link between some applications. What I want to do is calling a c++ program installed on a server into a webservice.
However I have found how to call a webservice in a c++ program but that's not what I am looking for.
How do you call a c++ code into a webservice ( I am using VS2013 btw) and is it relevant to do that.

So my question is : How do you call a c++ code into a webservice ( I am using VS2013 btw) and is it relevant to do that.
A web service is a service accessible remotely, which publishes several "endpoints".
Each endpoint corresponds to a function call (possibly implemented in C++).
To call a webservice endpoint, you must serialize the input parameters of the endpoint in a format accepted by the web service (in practice, this usually means generating a SOAP/XML document that contains the values of the parameters), then sending the serialized document to the server. The server then de-serializes the parameters, calls the function, serializes the result, and sends it as a response.
Webservices publish their endpoints (their accessible/callable APIs) in another XML standard, called WSDL, and public web services are usually listed in a public directory.
For this you will need a networking library usable in C++ (see gSoap), or an implementation of your own, on top of a networking library (see boost::asio).

It depends on in which language your web service is coded.
If it is PHP, see the function system to run another programme that you can code in any language you want (including C++ then).
If it is C/C++ on Linux, see the functions fork/exec's to create a new process and run another programme in that new process.
If it is C#, see this tutorial on Process.Start.
If it is Python, see the subprocess package from the standard library.
Anyway, if your web service is in C++ and that the code you want to execute is in the same programme, you can just do a function call in your web service's method.

Related

Is there a way to stop auto publish of a JAXWS webservice?

This is with respect to a JAXWS webservice. In a library (jar), besides many other classes, I have all the classes generated by wsimport, and the implementation class.
Two separate (EAR) applications depend on this library for different reasons.
In one application, I would like the webservice to be not started (not available), in the other application I would like the webservice to be up and running.
I did not write any Java code explicitly to start the webservice. I think, since the implementation class has #WebService annotation, and so, the environment automatically makes the webservice available.
If instead there is a way to manually start (publish) the webservice, and not use the automatic means, then we can do the manual publishing/starting in one of the application where it is desired.
Any ideas?

Invoking servlet from Java GUI application?

I know that similar questions have been asked before, but I would like to know if you can actually call a Servlet to do some work made on an EJB module, and then return the data to the standalone Java GUI application.
The requirement of the project says that both a standalone Java GUI client application, and a web client application should access a Servet to do their work, that is update and retrieve data from a database.
Does it make sense to use servlet for the GUI client to access the EJB, or why not access the EJB directly from the stand alone GUI application without invoking the Servlet at all.
Yes, you could call a servlet which in turn calls an EJB.
But you can call an EJB directly from a stand-alone application as well. If your servlet returns HTML markup (content type "text/html" - for human beings), you will have to parse it (requires effort) to get the same result. Every time the markup changes, your client has to be changed as well.
Even if there is a firewall in between (= direct RMI is not possible), you can use "RMI over http(s)", and there is a HTTP based naming service as well (JBoss offers this functionality).
On the other hand, if you mean a servlet which implements a web service which returns XML or JSON, it's a valid approach, especially if clients from other languages (C++ for example) are involved. Another advantage is that you can read the result using a browser (no need for a special RMI client). In that case have a look at available tutorials to implement a webservice in Java

Is there any problems when using Delphi to create Web-Service client?

I plan to start developing web-service client using Delphi XE. It looks like creating web-service client on delphi is easy to do.
Is there any bugs or problems when creating WebService on Delphi XE?
Is there any problems with other versions of Delphi (not XE) ?
(To create web-service i plan using WSDL-importer dialog)
Please, place Delphi version, you used to create web-service in answer.
I have created several webservice-clients in Delphi, all by using the wsdl. I have not encountered any problems so far. I have encountered some small problems, but nothin that couldn't be resolved with Google or Stackoverflow :-)
It depends. To answer your last question first, later versions of Delphi are better at generating a Web service client than earlier versions.
As for your first question. I have also created a number of Web service clients (and servers) using various versions of Delphi (most recently, Delphi 2007 and Delphi XE, though I also used Delphi 6, Delphi 7, and Delphi 2005). When the Web service methods use simple data types in its method parameters and return values (strings and integers), Delphi often does a good job of generating the client code using the WSDL importer. When complex data types are involved (objects, for example), it might be more challanging. For example, if the Web service uses complex types, and the WSDL is the only source of information about those types (you did not create the Web service, there is no documentation, or you cannot get the source code to it), it might take more work. It really depends on how complex the complex type is.
Additionally, if the Web service employs additional features such as authentication or other specialized headers, you will have to manually modify the code created by the WSDL importer. However, as birger noted, most of these issues can be resolved with research.
On the other hand, if the Web service was created in Delphi, it is usually very easy to create the Web service client.

How to connect a C++ program to a WCF Service?

In the place I work there are some software written in C# and some written in C++ (the most important ones). Some time ago we decided it would be a good idea to track any possible problem in the software, by sending stack trace and exception information over a web service. So I came with a WCF Service, that gets the information and store them on a database and send an automatic e-mail. It worked, we had to secure it through password, it's done, but now I want our other software, the one written in C++, to use this webservice (this software is used both on windows and linux, so we can't just make a call to another software in the user machine).
I've googled about it, and found this tutorial on how to use gSOAP, which so far didn't help me very much (lots of errors, it is not very detailed, and the web.config file is impossible to read). I was wondering if is there any other way to achieve this. In adition, since I'm using authentication on my webservice, it now has a wsHttpBinding (which AFAIK isn't supported by gSOAP).
Can you guys help me out?
Since your WCF service is in C# with .NET, and the only issue is getting the C++ application to be able to talk to it, one way is to follow the advice in REST / SOAP Endpoints for a WCF service and related articles.
Your C# programs continue to have the full SOAP access to your service.
Your C++ programs could do something like this for REST access:
"Browse" to the HTTP GET URL for the service command you wanted.
Then toss (or parse and use) whatever response came back.
It is a pretty minimal change to your WCF service to offer both SOAP and REST.
The REST ability opens your service to JavaScript as well as C++ clients.
You may need to restrict the interface to simple data, or class objects that are easy to parse in C++.
Will the machines running the C++ applications have the .NET Framework installed?
Check out: Create WCF service for unmanaged C++ clients

What does it mean "to write a web service"?

I just asked a question about whether it was possible to write a web-page-checking code and run it from free web server, and one supporter answered and said that it was possible only if I run "a web service" as simple script won't do that. He also suggested that I used Google App Engine service. I wonder what does it mean to write a "web service" and how is it different from writing a script?
A web service essentially provides the capability of RPC (Remote Procedure Calling) on top of the protocol of the web (HTTP). A URL implements an API which accepts a set of function arguments and returns a value. Different approaches are used to implement this RPC mechanism on top of HTTP protocol. XML-RPC defines a simple mechanism to specify the arguments and response using XML. SOAP is a much advanced version of XML-RPC. JSON-RPC lets you specify the procedure arguments and return values using JSON (JavaScript Object Notation).
Several programming languages come with built-in support for developing and working with web services. For example in Python, xmlrpclib provides the client side functionality of XML-RPC protocol. The XmlRpcServer library in Python makes it very easy to develop an XML-RPC based web server. Web services are interoperable in the sense that the client and server can be easily implemented in different programming languages and they don't need to worry about the details of each other.
Web services are different from other RPC mechanisms like COM/CORBA/JAVA's RMI. These RPC mechanism use binary data for exchange of arguments and results. The web services uses text oriented protocols like XML/JSON to implement the RPC protocol. Hence they are heavier from the perspective of communication overhead. They are still very good for development of loosely coupled systems. One big advantage they have is the fact that they are not tied to a specific programming language.
By "web service" one normally refers to a service available through HTTP protocol. The protocol sitting on top of HTTP can vary (XML, SOAP, JSON etc.).
But of course one can "complicate" the definition at will :-)
This is example of web service: http://www.webservicex.net/CurrencyConvertor.asmx?op=ConversionRate
When you scroll down you will see you can supply two parameters and get result back. Webservices can support different methods of communication. You can communicate with it using XML, SOAP, or HTTP GET/POST.
So web-service is a special type of script which main function is to expose method to public use (you can set access permissions a well), perform calculations on server-side and return output.