Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC Application and Web service

MFC Application and Web service

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++tutorialquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BadJerry
    wrote on last edited by
    #1

    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!

    L C 2 Replies Last reply
    0
    • B BadJerry

      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!

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      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

      B 1 Reply Last reply
      0
      • L 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

        B Offline
        B Offline
        BadJerry
        wrote on last edited by
        #3

        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!

        L 1 Reply Last reply
        0
        • B BadJerry

          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!

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • B BadJerry

            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!

            C Offline
            C Offline
            Christopher Duncan
            wrote on last edited by
            #5

            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

            B 1 Reply Last reply
            0
            • C Christopher Duncan

              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

              B Offline
              B Offline
              BadJerry
              wrote on last edited by
              #6

              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

              C 1 Reply Last reply
              0
              • B BadJerry

                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

                C Offline
                C Offline
                Christopher Duncan
                wrote on last edited by
                #7

                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

                B 1 Reply Last reply
                0
                • C Christopher Duncan

                  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

                  B Offline
                  B Offline
                  BadJerry
                  wrote on last edited by
                  #8

                  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!

                  C 1 Reply Last reply
                  0
                  • B BadJerry

                    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!

                    C Offline
                    C Offline
                    Christopher Duncan
                    wrote on last edited by
                    #9

                    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

                    B 1 Reply Last reply
                    0
                    • C Christopher Duncan

                      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

                      B Offline
                      B Offline
                      BadJerry
                      wrote on last edited by
                      #10

                      Yes that's the direction we're going towards I think... I simply it won't be too slow. If it proves to of any interest for the community, I'll report back. Keep watching this column! Ta!

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups