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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Consumig WebService from C++.

Consumig WebService from C++.

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++comtutorialquestion
4 Posts 2 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.
  • M Offline
    M Offline
    Mike Doner
    wrote on last edited by
    #1

    Hi all, I'm trying to find the best/easiest way to consume a WebService in my application which is written in C/C++. I've seen and tried numerous examples over the course of the last few days, and there seems to be pros and cons no matter which way I go. I thought I'd ask you folks your opinion. I turned on the "/crl" option on in my project, and added a WebReference. I was able to call the WebService without any problems, but I'm unsure how to handle exceptions when something goes wrong (ie: address is no longer valid). If everything is up and running and things are successful, there are no problems.

    Test_WSService obtws;

    try
    {
    obtws.Url = "http://localhost:8088/mockObtain\_WSSoapBinding1";
    obtws.UpdateObject ( "A", "B", "C" );
    }
    catch ( ??? )
    {
    }

    With whatever route I go with, I'd like to be able to change the destination url on the fly as this will be specified in a user-modifiable configuration file. My knowledge of COM is almost nil. I've seen examples where a developer did all the WebService consuming in a C# dll, and just called that from the C++ application as well. Whats your past experiences, recommendation? Anything you could forward would be helpful. Cheers. Mike.

    L 1 Reply Last reply
    0
    • M Mike Doner

      Hi all, I'm trying to find the best/easiest way to consume a WebService in my application which is written in C/C++. I've seen and tried numerous examples over the course of the last few days, and there seems to be pros and cons no matter which way I go. I thought I'd ask you folks your opinion. I turned on the "/crl" option on in my project, and added a WebReference. I was able to call the WebService without any problems, but I'm unsure how to handle exceptions when something goes wrong (ie: address is no longer valid). If everything is up and running and things are successful, there are no problems.

      Test_WSService obtws;

      try
      {
      obtws.Url = "http://localhost:8088/mockObtain\_WSSoapBinding1";
      obtws.UpdateObject ( "A", "B", "C" );
      }
      catch ( ??? )
      {
      }

      With whatever route I go with, I'd like to be able to change the destination url on the fly as this will be specified in a user-modifiable configuration file. My knowledge of COM is almost nil. I've seen examples where a developer did all the WebService consuming in a C# dll, and just called that from the C++ application as well. Whats your past experiences, recommendation? Anything you could forward would be helpful. Cheers. Mike.

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

      Mike Doner wrote:

      With whatever route I go with, I'd like to be able to change the destination url on the fly as this will be specified in a user-modifiable configuration file.

      Mike Doner wrote:

      I've seen examples where a developer did all the WebService consuming in a C# dll, and just called that from the C++ application as well.

      Mike Doner wrote:

      Whats your past experiences, recommendation?

      Yes, we have done the same thing. I used WSDL[^] to generate a C# proxy source file then built that into an assembly with a wrapper class that changes the URL based on incoming parameters. This wrapper is then used by C++/CLI DLL Project that exports a native C++ class that is used by native EXE projects. The WSDL generated class derives from System.Web.Services.Protocols.SoapHttpClientProtocol which has a .URL property.

      M 1 Reply Last reply
      0
      • L led mike

        Mike Doner wrote:

        With whatever route I go with, I'd like to be able to change the destination url on the fly as this will be specified in a user-modifiable configuration file.

        Mike Doner wrote:

        I've seen examples where a developer did all the WebService consuming in a C# dll, and just called that from the C++ application as well.

        Mike Doner wrote:

        Whats your past experiences, recommendation?

        Yes, we have done the same thing. I used WSDL[^] to generate a C# proxy source file then built that into an assembly with a wrapper class that changes the URL based on incoming parameters. This wrapper is then used by C++/CLI DLL Project that exports a native C++ class that is used by native EXE projects. The WSDL generated class derives from System.Web.Services.Protocols.SoapHttpClientProtocol which has a .URL property.

        M Offline
        M Offline
        Mike Doner
        wrote on last edited by
        #3

        Thank you for your reply. As I said, this is all pretty new to me, so I'm doing a bit of feeling around for getting it to work. I was able to create a C# proxy without any problems, and from a C# project, I can call the WebService. I've created a C# Class that has a WebService, with all the parameters I need, including setting the URL. Now, to call this from the C++ side... Were you suggesting all the C# stuff being in a .DLL, then calling those functions from the C++ side? Is there a way to put a .cs into a project and have it all compile together into one project? I found a sample online (may have been here on CP), that has a MFC project, and it shows how to use a C# object from the MFC side, including all the string marshalling. Is there an easier way? Thanks again... I'm getting closer! ;-)

        L 1 Reply Last reply
        0
        • M Mike Doner

          Thank you for your reply. As I said, this is all pretty new to me, so I'm doing a bit of feeling around for getting it to work. I was able to create a C# proxy without any problems, and from a C# project, I can call the WebService. I've created a C# Class that has a WebService, with all the parameters I need, including setting the URL. Now, to call this from the C++ side... Were you suggesting all the C# stuff being in a .DLL, then calling those functions from the C++ side? Is there a way to put a .cs into a project and have it all compile together into one project? I found a sample online (may have been here on CP), that has a MFC project, and it shows how to use a C# object from the MFC side, including all the string marshalling. Is there an easier way? Thanks again... I'm getting closer! ;-)

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

          Mike Doner wrote:

          Were you suggesting all the C# stuff being in a .DLL, then calling those functions from the C++ side?

          Sort of. C++/CLI provides the combined use of Native Code and Managed Code. So it creates a very natural environment for marshalling. By building your C# proxy into an assembly it becomes available to C++/CLI projects as a Managed class when you add the Reference to the assembly.

          Mike Doner wrote:

          Is there an easier way?

          An easier way to perform Marshalling? No, marshalling is nothing new[^]. It is what it is, we can't change it.

          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