MFC Application and Web service
-
I have this existing MFC application. I'd like some external C#/Silverlight application to communicate with it. Does anyone know how to add code so it can act as web service? Any pointer to articles / sample is welcome! Thanks in advance!
BadJerry wrote:
Does anyone know how to add code so it can act as web service?
That question gives the impression you don't know the first thing about web services. If you are hoping there is a code copy/paste solution for you I believe you are mistaken. This would be a good place to start but it's just scratching the surface.[^]
led mike
-
BadJerry wrote:
Does anyone know how to add code so it can act as web service?
That question gives the impression you don't know the first thing about web services. If you are hoping there is a code copy/paste solution for you I believe you are mistaken. This would be a good place to start but it's just scratching the surface.[^]
led mike
ohhh you are being harsh ... I know roughly a web service is. But true not that much. I know it's stateless and that you can pass it some SOAP command... What I want to do is provide an API to my MFC application... some way of communicating between a web app and my app... A web service seemed a good idea - do say if I am wrong!
-
ohhh you are being harsh ... I know roughly a web service is. But true not that much. I know it's stateless and that you can pass it some SOAP command... What I want to do is provide an API to my MFC application... some way of communicating between a web app and my app... A web service seemed a good idea - do say if I am wrong!
BadJerry wrote:
do say if I am wrong!
I can't say and wasn't saying a Web Service is the wrong solution.
BadJerry wrote:
ohhh you are being harsh
I'm not being harsh, the reality of what it takes to have a Web Service might be harsh but I didn't invent them. :)
BadJerry wrote:
I know roughly a web service is. But true not that much.
Well then I guess you better get to reading eh? That Wiki page has a bunch of links at the bottom. Should keep you busy for quite a while. Good luck
led mike
-
I have this existing MFC application. I'd like some external C#/Silverlight application to communicate with it. Does anyone know how to add code so it can act as web service? Any pointer to articles / sample is welcome! Thanks in advance!
Hi, Jerry. You're looking at a multi part solution. First, create a new C# Web Service project in Visual Studio. If you're comfortable with C#, writing the web service code is pretty straightforward. Just be sure to keep the member functions public and use the [WebMethod] tag for the routines you want to make publicly available via the service. After you've created your web service, go to your C++ app and in the Solution Explorer of Visual Studio, add a Web Reference pointing to your web service (you'll get a dialog prompting you for services in this project, on local host, or a remote url). This web reference creates a C++ proxy class header file. You can then use this class in your C++ app to talk to the web service API. You'll need to use BSTRs instead of CStrings, etc., but by looking at the proxy header file the params will be obvious to you. I don't have any ready articles to point you to, but if you search for them on each of the steps I've mentioned, you should find plenty of starter code to get you going. Hope this helps,
Christopher Duncan Author of The Career Programmer and Unite the Tribes www.PracticalUSA.com
-
Hi, Jerry. You're looking at a multi part solution. First, create a new C# Web Service project in Visual Studio. If you're comfortable with C#, writing the web service code is pretty straightforward. Just be sure to keep the member functions public and use the [WebMethod] tag for the routines you want to make publicly available via the service. After you've created your web service, go to your C++ app and in the Solution Explorer of Visual Studio, add a Web Reference pointing to your web service (you'll get a dialog prompting you for services in this project, on local host, or a remote url). This web reference creates a C++ proxy class header file. You can then use this class in your C++ app to talk to the web service API. You'll need to use BSTRs instead of CStrings, etc., but by looking at the proxy header file the params will be obvious to you. I don't have any ready articles to point you to, but if you search for them on each of the steps I've mentioned, you should find plenty of starter code to get you going. Hope this helps,
Christopher Duncan Author of The Career Programmer and Unite the Tribes www.PracticalUSA.com
Hi Christopher, Thanks for your input. Yes I have managed to create a Web Service in C# in the past and it is straightforward. But what I want to do is the other way round. I would like a C# application or silverlight or whatever to communicate with my MFC application (a big mother who acts a bit like a service). I want to provide an API to this MFC app in other words. In the past, I would have used a COM object but I'd like something more future proof - hence a web service. The web service would have methods to check the state of the MFC app or to request the app to do something. That's it... and I am wondering about which architecture I should go for. Any advise welcome! Jerry
-
Hi Christopher, Thanks for your input. Yes I have managed to create a Web Service in C# in the past and it is straightforward. But what I want to do is the other way round. I would like a C# application or silverlight or whatever to communicate with my MFC application (a big mother who acts a bit like a service). I want to provide an API to this MFC app in other words. In the past, I would have used a COM object but I'd like something more future proof - hence a web service. The web service would have methods to check the state of the MFC app or to request the app to do something. That's it... and I am wondering about which architecture I should go for. Any advise welcome! Jerry
I'm not sure that a web service is really a relevant solution for what you're looking to do. Sounds more like you're looking for an appropriate choice for inter process communications. Since the MFC app is doing all the heaving lifting and you have .NET apps that you want to talk to it, COM is actually a reasonable solution (I can't believe I just called COM reasonable). Alternatively, you could set up communication through sockets or named pipes (haven't tried accessing shared memory yet in the .NET world. Trying to force this into a web service architecture just because it's the current trendy thing is rarely a good idea froma technical point of view. Of course, resume enhancement is another matter entirely. :)
Christopher Duncan Author of The Career Programmer and Unite the Tribes www.PracticalUSA.com
-
I'm not sure that a web service is really a relevant solution for what you're looking to do. Sounds more like you're looking for an appropriate choice for inter process communications. Since the MFC app is doing all the heaving lifting and you have .NET apps that you want to talk to it, COM is actually a reasonable solution (I can't believe I just called COM reasonable). Alternatively, you could set up communication through sockets or named pipes (haven't tried accessing shared memory yet in the .NET world. Trying to force this into a web service architecture just because it's the current trendy thing is rarely a good idea froma technical point of view. Of course, resume enhancement is another matter entirely. :)
Christopher Duncan Author of The Career Programmer and Unite the Tribes www.PracticalUSA.com
Not too much thinking of my resume but yes, I am trying to get out of my comfort zone... and I'd like the app to have a zingy Silverlight front end ;) And if it's a web service it means it's easier to document and for other programmers to be involved rather than named pipes or sockets... a bit more OO... Thanks again for your advices!
-
Not too much thinking of my resume but yes, I am trying to get out of my comfort zone... and I'd like the app to have a zingy Silverlight front end ;) And if it's a web service it means it's easier to document and for other programmers to be involved rather than named pipes or sockets... a bit more OO... Thanks again for your advices!
Well, if you have your heart set on a web service, then probably the best approach is to expose functionality in the MFC app via COM and have the web service act as an intermediary, making COM calls to MFC and passing the results back to the caller of the web service. I don't see any reason why that shouldn't work for you. Have fun! :)
Christopher Duncan Author of The Career Programmer and Unite the Tribes www.PracticalUSA.com
-
Well, if you have your heart set on a web service, then probably the best approach is to expose functionality in the MFC app via COM and have the web service act as an intermediary, making COM calls to MFC and passing the results back to the caller of the web service. I don't see any reason why that shouldn't work for you. Have fun! :)
Christopher Duncan Author of The Career Programmer and Unite the Tribes www.PracticalUSA.com