I decided to Dive into the WWSAPI Beta and see how I could call a simple HelloWorld Applications. Here are my adventures:
I installed Windows 7 in a HyperV VM and installed Visual Studio 2008 SP1.
I downloaded the Windows 7 SDK and attached the .ISO image as the CD drive and installed it.
I then ran the Windows SDK Configuration Tool and selected the Windows 7 SDK configuration.
Then I downloaded this wsdl: http://jsandersrocks.members.winisp.net/WebServiceTest/WebService.asmx?WSDL
I created a C++ console application with the defaults from the template and named it WWSAPITest.
I created a subdirectory called 'wsdl' in my new project and copied the WSDL into this directory and called it MyWebService.wsdl
Next I opened a CMD Shell Window from the Microsoft Windows SDK v7.0 menu.
I Navigated to the above directory were the WSDL file is and typed: wsutil *
This generated the .h and .c file that I then included in my project.
Just for fun I decided to build the Project to see if I had any errors.
I got these errors:
c:\users\jsanders\documents\visual studio 2008\projects\wwsapitest\wsdl\mywebservice.wsdl.c : fatal error C1853: 'Debug\WWSAPITest.pch' precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa)
There are C files in the project now so I turned off precompiled header (under C++ Precompiled Headers) option and did a clean and rebuild of the project. I then got these errors:
MyWebService.wsdl.obj : error LNK2019: unresolved external symbol _WsCall@32 referenced in function _WebServiceSoap_HelloWorld@28
MyWebService.wsdl.obj : error LNK2019: unresolved external symbol _WsCreateServiceProxyFromTemplate@40 referenced in function _WebServiceSoap_CreateServiceProxy
MyWebService.wsdl.obj : error LNK2019: unresolved external symbol _WsCreateServiceEndpointFromTemplate@60 referenced in function _WebServiceSoap_CreateServiceEndpoint
I Included WebServices.lib in the input libraries in the Linker options rebuilt and then the project built fine.
Now the complete code listing for your enjoyment (Copy Code):
// WWSAPITest.cpp : Defines the entry point for the console application.
//
#include
int
HRESULT hr;WS_ERROR* error;WS_HEAP* heap;WS_SERVICE_PROXY* serviceProxy;hr = S_OK;error = NULL;heap = NULL;serviceProxy = NULL; // Creating error objecthr = WsCreateError(NULL, 0, &error);if (FAILED(hr)){ wprintf (L"Failed to create Error object\n"); return -1; }// Creating heap handlehr = WsCreateHeap(10000000, 0, NULL, 0, &heap, error);if (FAILED(hr)) { wprintf (L"Failed to create Heap object\n"); if (heap != NULL) { WsFreeHeap(heap); heap = NULL; } if (error != NULL) { WsFreeError(error); error = NULL; } return -1;} WS_HTTP_BINDING_TEMPLATE templateValue = {};hr=WebServiceSoap12_CreateServiceProxy( &templateValue, NULL, 0, &serviceProxy, error);if (FAILED(hr)) { WsFreeHeap(heap); WsFreeError(error); return -1;}WS_ENDPOINT_ADDRESS address = {};WS_STRING Url = WS_STRING_VALUE(L"http://jsandersrocks.members.winisp.net/WebServiceTest/WebService.asmx");
HRESULT hr;WS_ERROR* error;WS_HEAP* heap;WS_SERVICE_PROXY* serviceProxy;hr = S_OK;error = NULL;heap = NULL;serviceProxy = NULL;
WS_HTTP_BINDING_TEMPLATE templateValue = {};hr=WebServiceSoap12_CreateServiceProxy( &templateValue, NULL, 0, &serviceProxy, error);if (FAILED(hr)) { WsFreeHeap(heap); WsFreeError(error); return -1;}WS_ENDPOINT_ADDRESS address = {};WS_STRING Url = WS_STRING_VALUE(L"http://jsandersrocks.members.winisp.net/WebServiceTest/WebService.asmx");
address.url = Url;hr = WsOpenServiceProxy(serviceProxy, &address, NULL, error);if (FAILED(hr)) { WsFreeServiceProxy(serviceProxy); WsFreeHeap(heap); WsFreeError(error); return -1;}WCHAR *aResult = NULL;hr= WebServiceSoap12_HelloWorld( serviceProxy, &aResult, heap, NULL, 0,NULL, error);if (SUCCEEDED(hr)){ wprintf(L"%s\n", aResult);}else { wprintf(L"failed\n");}if (serviceProxy != NULL){ WsCloseServiceProxy(serviceProxy, NULL, error); WsFreeServiceProxy(serviceProxy); serviceProxy = NULL;}if (heap != NULL){ WsFreeHeap(heap); heap = NULL;}if (error != NULL){ WsFreeError(error); error = NULL;}return 0;
}
This console app ran and returned the expected 'Hello World'!
Let me know if you found this useful!