views:

254

answers:

6

Is it possible to exchange web-services over socket programs written in C/C++?

The data to exchange are in the from of xml/soap message.

A: 

Yes, it is possible. You can write code that uses standard POSIX sockets, so it will be portable between windows and unix-like operating systems. But you'll very likely want to build up some layers of abstraction to make it all easier on yourself, or use an existing library.

As for talking to webservices, you will need some sort of XML/Json/whatever parser. SAX is a good XML parser, and I'm pretty sure there is a C interface for that. But it all depends on the data format.

Mike Weller
thanks for your reply. this is what I am looking for. I want to add some layers of abstraction on the top of sockets. Does it possible to SOAP ?
make
actually, I am using BSD sockets, not POSIX sockets
make
BSD sockets are what I meant by POSIX. You could handle SOAP, but it is going to be VERY painful to do it yourself. I would suggest you google for some C/C++ APIs or tools.
Mike Weller
thanks! that confirms me what I am trying to do. I am trying to handle SOAP messages with socket programs written in C/C++. By using gSOAP I got confused and this is why I posted this question.
make
+1  A: 

Put simply, yes. I suppose you likely want more detail than just a "yes", but the question is far too general to garner any much more specific answer.

You mention UDP and even raw sockets, but it's not clear to me why. "Web Services" are typically HTTP, which means they're over TCP.

I think at this point in your learning there are just far too many things for you to learn that it sounds like maybe you just don't even know the questions to ask. Perhaps if you could be more specific about what you're trying to accomplish folks could provide more helpful answers.

Chris Cleeland
wow, you might be a genius. 1) you should know that I am not the person you described. you may be confusing a lot. UDP is different than TCP and different than RAW. ok! You could say TCP/IP, ok! 2) I don't ask direct question but open question. why? because if i ask a direct question, the answer will be limited to that specific topic. 3) I am asking such questions to learn ...
make
it wasn't me how said raw. it was the person who edited my question...
make
+1  A: 

http://www.securitytube.net/Socket-Programming-Basics-Presentation-video.aspx

Newb
Thanks! unfortunately I already know what sockets are made for and I already learned how to program them...
make
So what are you asking, then? If you know how to use sockets, you know that you can use them to send data, which is what your question is asking.
ChrisInEdmonton
see the question below
make
+1  A: 

If you're using web services, you'll spend more time writing socket code than you will writing code to consume the web services.

If it is SOAP web services, use gSoap (http://www.cs.fsu.edu/~engelen/soap.html). If it is something like REST web services or plain data exchange over an HTTP post without all the SOAP protocol stuff, libcurl (http://curl.haxx.se/) is easy to use too.

Both libraries will work on Windows and Linux.

Nathan
thanks a lot for your reply. this is what I was expecting to hear in order to be sure about what I am trying to do. I am using gSOAP and I got confused. I have already my socket programs witten in C/C++ and I want to exchange SOAP messages through them. is this then possible with it???
make
I don't know why you'd want to do that. gSoap deals with the socket handling itself on both the client and server side. I don't know that it has abstracted a socket replacement API inside of it to allow you to plug in your own socket code. I suppose, strictly speaking, that it should technically work if it has a mode where it works over non-HTTP connections. I believe it does (I've never used it), which means you could technically use gSoap as a tool to just deal with the data and implement your own transport. SOAP is not limited to using the HTTP protocol.
Nathan
Thanks again for your help. the problem is not about the protocol but if I use gsoap, it would generate client and server codes. As I have already wrote my programs, I want to use web-services as another layer that my programs use.
make
A: 

Maybe you want to try CGI? With it it's possible to create a website in C++, without worrying about sockets.. Your compiled executable will be executed by the web server every time a page is requested, and the output of said executable will be sent to the web browsers.

So you can do stuff like cout << "<html>";.

[I know that this is not exactly what you asked but your question isn't very clear, and I didn't want to repeat something already said!]

Andreas Bonini
A: 

First, I wan't me who made the question unclear and sorry if the question was incomplete ...
Let's then make it more clear. When we have an XML/SOAP message as follow:
...
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
<soap:Body>
...
</soap:Body>
</soap:Envelope>

and we have got programs that are already written in C/C++ and exchange data through sockets, how can we than use those programs to exchange XML/SOAP messages.
Hope the question is now clear and thanks for your replies

make
This is not an answer. If you wish to edit your question, you can do that!
ChrisInEdmonton
I know but I posted that answer to make the question clear
make