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