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. Accessing a web Service from VC++ application

Accessing a web Service from VC++ application

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
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
    Member 534357
    wrote on last edited by
    #1

    I added a web service to my VC++ application. To access it from within my project I do the following code: WeatherService::CWeatherService *ws = new WeatherService::CWeatherService(); HRESULT hr = ws->GetWeather("KNEL"); if(hr == E_FAIL) AfxMessageBox("Unable to retrieve current weather, Invalid Station Code", MB_OKCANCEL); It's returning an E_FAIL by the SendRequest function. Any ideas as to what I am doing wrong? It works fine when I call it from a managed C++ application. Thanks

    A 1 Reply Last reply
    0
    • M Member 534357

      I added a web service to my VC++ application. To access it from within my project I do the following code: WeatherService::CWeatherService *ws = new WeatherService::CWeatherService(); HRESULT hr = ws->GetWeather("KNEL"); if(hr == E_FAIL) AfxMessageBox("Unable to retrieve current weather, Invalid Station Code", MB_OKCANCEL); It's returning an E_FAIL by the SendRequest function. Any ideas as to what I am doing wrong? It works fine when I call it from a managed C++ application. Thanks

      A Offline
      A Offline
      Antti Keskinen
      wrote on last edited by
      #2

      Humm.. I tried the same by using XMethods' WeatherService (gets the weather by zipcode, found "http://www.xmethods.net/sd/2001/TemperatureService.wsdl") and it works properly. As I have no idea what web service you are consuming (no link ?), then it is just about impossible to tell if your parameters are correct. I, however, suggest checking the parameters. It looks like you are getting the weather for a station named "KNEL", but you are not saving the result value anywhere ? Check the function parameters. I believe that the parameter should be two-fold: upon input, it specifies the station name, and upon output, it gives you the weather. I believe that it (GetWeather) requires a BSTR value as the first parameter. If you get into a dead-end when using a BSTR, paste a link to the web service into this forum, and I'll do a quick-check on how to call it properly.. Moreover, a little more detailed code paste from the function that is calling the web service would be useful. Are you initializing COM, for example ? -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

      M 1 Reply Last reply
      0
      • A Antti Keskinen

        Humm.. I tried the same by using XMethods' WeatherService (gets the weather by zipcode, found "http://www.xmethods.net/sd/2001/TemperatureService.wsdl") and it works properly. As I have no idea what web service you are consuming (no link ?), then it is just about impossible to tell if your parameters are correct. I, however, suggest checking the parameters. It looks like you are getting the weather for a station named "KNEL", but you are not saving the result value anywhere ? Check the function parameters. I believe that the parameter should be two-fold: upon input, it specifies the station name, and upon output, it gives you the weather. I believe that it (GetWeather) requires a BSTR value as the first parameter. If you get into a dead-end when using a BSTR, paste a link to the web service into this forum, and I'll do a quick-check on how to call it properly.. Moreover, a little more detailed code paste from the function that is calling the web service would be useful. Are you initializing COM, for example ? -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

        M Offline
        M Offline
        Member 534357
        wrote on last edited by
        #3

        The code for GetWeather is as follows: public void GetWeather(string stationcode) { Weather weather = new Weather(); GetWeather getweather = new GetWeather(); weather = getweather.GetWeatherObject(stationcode); } Yes it does require a BSTR as the parameter & it does not return any value, basically all the function does is update a database with the latest weather. It seems to be failing in the atlSoap.h file in the SendRequest function when it tries to navigate to the url, it fails in sending the message to the server os the wuestion is WHY?

        A 1 Reply Last reply
        0
        • M Member 534357

          The code for GetWeather is as follows: public void GetWeather(string stationcode) { Weather weather = new Weather(); GetWeather getweather = new GetWeather(); weather = getweather.GetWeatherObject(stationcode); } Yes it does require a BSTR as the parameter & it does not return any value, basically all the function does is update a database with the latest weather. It seems to be failing in the atlSoap.h file in the SendRequest function when it tries to navigate to the url, it fails in sending the message to the server os the wuestion is WHY?

          A Offline
          A Offline
          Antti Keskinen
          wrote on last edited by
          #4

          Could you please post a link to the actual web service, or is it for private use only ? It is nearly impossible to say anything about the actual problem before debugging it personally. It looks like that the problem in the actual service, that it is unable to handle the request. But why, then again, impossible to say. Perhaps the implementation of the web service isn't programmed properly to support VC++ callers. The 'string' variable looks like .Net Framework variable, and as such, it is not directly compatible with the BSTR variables of VC++ COM architecture. Unfortunately, I cannot help you further until I can give a few shots at using the web service myself. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.

          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