Hosting a Axis2/C Web Service in a C++ application and calling into it

gongchengshi's picture
I want to use web service as middle-ware between a C++ application I have written and external web service clients. I don't want to have to provide additional IPC between my application and the Web Server process that is exposing my web service. What I want to do is run my Axis2/C Web Service in the same process space as my application so no IPC is required. What I have done is turned the Axis2 Simple HTTP Server into a library and linked it with my application. I run the server as a thread in my app's process in order to get it into the same process space. Then I needed to send data from my application to my web service. The web service gets linked in dynamically as a DLL so the only way I could see to do this was to expose some functions in my service's DLL. I then altered axutil_class_loader_create_dll() in class_loader.c to look for my service DLL by name and use GetProcAddress to get a function pointer to my exposed functions. I then use these to call into my service DLL. The problem is I don't like having to make so many changes to the Axis2/C source code in order to send data to my web service. This seems like a fairly common problem. Is there a more elegant way of doing this? Perhaps something in the API?
uthaiyashankar's picture

Normally, you can expose

Normally, you can expose your functions from dll (which you have already done) and write a web service to use those functions. In this case, you don't need to modify any of Axis2/C code. you have to link your dll to the service.dll. When a request is received by the system, it will be given to the web service, which will pass the request to your application.
uthaiyashankar's picture

You can use WSF/C++ as well,

You can use WSF/C++ as well, since your application is a C++ application. WSF/C++ uses Axis2/C internally.
gongchengshi's picture

Some clarification and details

Thanks for your reply. I am making a publish/subscribe system using web services. Here is the basic architecture: I have an Axis2/C Web Service that is running. When a subscription request comes in it provides the URI of an endpoint to send data to when new data is published. When new data is published, my code loops through the list of subscribers and sends the data to all that have subscribed. Right now I plan to have subscribers run their own web service that my app can send data to. So each subscriber has one web service running and one client. My publisher has a web service running and is a client to multiple web services. So... The problem isn't so much handling requests from web service clients. My problem is getting my published data from a data producer into the same process that knows about the data consumers. Which is my Axis2/C Web Service because that is the part of the system that handles subscribe/unsubscribe requests. I know that web services are usually only used for request/response type communications, but publish/subscribe can't be the only reason for pushing data into a web service process instead of simply fetching it, say from a database, when a request comes in. I haven't done much work with C/C++ DLL's in the past so I may be completely retarded about this. From what I understand DLL's, like anything else, can't call into the code that loaded them without providing a callback.
gongchengshi's picture

I would but...

You can't make a web service with WSF/C++ at this point. Only clients. I found that out the hard way after downloading and building WSF/C++.
gongchengshi's picture

Why not Savan/C ws-eventing?

I just realized the first response to my post above will be: "Why don't you just use Savan/C?" Well the ws-eventing specification is nice but it is very limited from what I can tell. In ws-eventing you subscribe to an "event" and the only information that you get when that event happens is that the event happened. In order to get the data associated with that event you have to go and request it from the web service. It doesn't really allow you to say "when my web service finds out about a new chunk of data, send that chunk of data to every person that is subscribed to it". Correct me if I am wrong though because I would love to use Savan/C if that solves my problems.
gongchengshi's picture

Handle to service dll

I guess all I need is a handle to the service dll. Then I can call directly into the dll from anywhere in my application right? The only problem there is that a service dll isn't loaded until the first request comes in.
gongchengshi's picture

I think this should work.

I can load my service dll before starting my web service. This works because both the linux/unix dlopen and Window's LoadLibrary that are used by axutil in Axis2/C just return the same handle to the so/dll. If my code has already loaded them them then Axis2/C will just the same handle to use for the web service initialization. I can then use this handle to my dll to call into my service so/dll. I just had to learn a little more about how DLLs work in the C runtime. Once I get my publish/subscribe stuff up and working I will write an article so others can learn how to do it too.
uthaiyashankar's picture

Use WSF/C++ 2.0.0

With WSF/C++ 2.0.0, you can write services as well.
gongchengshi's picture

Awesome

That must be new. I downloaded it about 3 months ago. I must have gotten version 1.0. I'll look into version 2.0.
library project main code
Learn Cloud
Learn
Cloud

The WSO2 Application Server is a reliable application server that can host your enterprise web applications. The WSO2 Application Server as a Service is offered in StratosLive, the WSO2 Platform as a Service. This article explains how a simple web application can be developed and deployed from Carbon Studio to the WSO2 Application Server...

Latest Webinar
Different groups within an organization need to monitor different Key Performance Indicators (KPIs) - An operations team will be interested in the response times of business services and loads of each service,..
Thursday, February 9th 2012, 09.00 AM (PST)

Thursday, February 9th 2012, 10.00 AM (GMT)