static void test_WsOpenServiceProxy(void) { WCHAR url[] = {'h','t','t','p',':','/','/','l','o','c','a','l','h','o','s','t','/'}; HRESULT hr; WS_SERVICE_PROXY *proxy; WS_HTTP_POLICY_DESCRIPTION policy; WS_ENDPOINT_ADDRESS addr; memset( &policy, 0, sizeof(policy) ); hr = WsCreateServiceProxyFromTemplate( WS_CHANNEL_TYPE_REQUEST, NULL, 0, WS_HTTP_BINDING_TEMPLATE_TYPE, NULL, 0, &policy, sizeof(policy), &proxy, NULL ); ok( hr == S_OK, "got %08x\n", hr ); addr.url.length = sizeof(url)/sizeof(url[0]); addr.url.chars = url; addr.headers = NULL; addr.extensions = NULL; addr.identity = NULL; hr = WsOpenServiceProxy( proxy, &addr, NULL, NULL ); ok( hr == S_OK, "got %08x\n", hr ); hr = WsCloseServiceProxy( proxy , NULL, NULL ); ok( hr == S_OK, "got %08x\n", hr ); WsFreeServiceProxy( proxy ); }
WCF::~WCF() { if (proxy){ WsCloseServiceProxy(proxy, NULL, NULL); WsFreeServiceProxy(proxy); } if (heap){ WsFreeHeap(heap); } if (error){ WsFreeError(error); } }
// // Close service proxy and clean up // void FlickrUploader::CloseWebProxy (WS_HEAP** heap, WS_SERVICE_PROXY** proxy, WS_ERROR** error) { if (proxy != nullptr && *proxy != nullptr) { WsCloseServiceProxy(*proxy, nullptr, nullptr); WsFreeServiceProxy(*proxy); } if (heap != nullptr && *heap != nullptr) { WsFreeHeap(*heap); } if (error != nullptr && *error != nullptr) { WsFreeError(*error); } }
// Main entry point int __cdecl wmain() { HRESULT hr = S_OK; WS_ERROR* error = NULL; WS_HEAP* heap = NULL; WS_SERVICE_PROXY* proxy = NULL; int result = 0; WS_ENDPOINT_ADDRESS address = {}; static const WS_STRING serviceUrl = WS_STRING_VALUE(L"net.tcp://localhost/example"); // Create an error object for storing rich error information hr = WsCreateError( NULL, 0, &error); if (FAILED(hr)) { goto Exit; } // Create a heap to store deserialized data hr = WsCreateHeap( /*maxSize*/ 2048, /*trimSize*/ 512, NULL, 0, &heap, error); if (FAILED(hr)) { goto Exit; } hr = WsCreateServiceProxy( WS_CHANNEL_TYPE_DUPLEX_SESSION, WS_TCP_CHANNEL_BINDING, NULL, NULL, 0, NULL, 0, &proxy, error); if (FAILED(hr)) { goto Exit; } // Initialize address of service address.url = serviceUrl; hr = WsOpenServiceProxy( proxy, &address, NULL, error); if (FAILED(hr)) { goto Exit; } hr = CalculatorBinding_Add( proxy, 1, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } wprintf( L"+1\n"); hr = CalculatorBinding_Add( proxy, 2, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } wprintf( L"+2\n"); hr = CalculatorBinding_Add( proxy, 3, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } wprintf( L"+3\n"); hr = CalculatorBinding_Add( proxy, 4, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } wprintf( L"+4\n"); hr = CalculatorBinding_Subtract( proxy, 5, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } wprintf( L"-5\n"); hr = CalculatorBinding_Total( proxy, &result, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } wprintf( L"====\n"); wprintf( L"%d\n", result); hr = CalculatorBinding_Clear( proxy, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } Exit: if (FAILED(hr)) { // Print out the error PrintError(hr, error); } if (proxy != NULL) { WsCloseServiceProxy( proxy, NULL, NULL); WsFreeServiceProxy( proxy); } if (heap != NULL) { WsFreeHeap(heap); } if (error != NULL) { WsFreeError(error); } fflush(stdout); return SUCCEEDED(hr) ? 0 : -1; }
// Main entry point int __cdecl wmain() { HRESULT hr = S_OK; WS_ERROR* error = NULL; WS_HEAP* heap = NULL; WS_SECURITY_TOKEN* securityToken = NULL; WS_SERVICE_PROXY* proxy = NULL; // declare and initialize an XML security token message security binding WS_XML_TOKEN_MESSAGE_SECURITY_BINDING xmlTokenBinding = {}; // zero out the struct xmlTokenBinding.binding.bindingType = WS_XML_TOKEN_MESSAGE_SECURITY_BINDING_TYPE; // set the binding type xmlTokenBinding.bindingUsage = WS_SUPPORTING_MESSAGE_SECURITY_USAGE; // set the binding usage // declare and initialize an SSL transport security binding WS_SSL_TRANSPORT_SECURITY_BINDING sslBinding = {}; // zero out the struct sslBinding.binding.bindingType = WS_SSL_TRANSPORT_SECURITY_BINDING_TYPE; // set the binding type // declare and initialize the array of all security bindings WS_SECURITY_BINDING* securityBindings[2] = { &sslBinding.binding, &xmlTokenBinding.binding }; // declare and initialize the security description WS_SECURITY_DESCRIPTION securityDescription = {}; // zero out the struct securityDescription.securityBindings = securityBindings; securityDescription.securityBindingCount = WsCountOf(securityBindings); int result = 0; WS_ENDPOINT_ADDRESS address = {}; static const WS_STRING url = WS_STRING_VALUE(L"https://localhost:8443/example"); address.url = url; // Create an error object for storing rich error information hr = WsCreateError( NULL, 0, &error); if (FAILED(hr)) { goto Exit; } // create an XML security token and set it on the relevant security binding hr = CreateXmlSecurityToken(&securityToken, error); if (FAILED(hr)) { goto Exit; } xmlTokenBinding.xmlToken = securityToken; // Create a heap to store deserialized data hr = WsCreateHeap( /*maxSize*/ 2048, /*trimSize*/ 512, NULL, 0, &heap, error); if (FAILED(hr)) { goto Exit; } // Create the proxy hr = WsCreateServiceProxy( WS_CHANNEL_TYPE_REQUEST, WS_HTTP_CHANNEL_BINDING, &securityDescription, NULL, 0, NULL, 0, &proxy, error); if (FAILED(hr)) { goto Exit; } // after the proxy is created, the security token handle can be freed if (securityToken != NULL) { WsFreeSecurityToken(securityToken); securityToken = NULL; } hr = WsOpenServiceProxy( proxy, &address, NULL, error); if (FAILED(hr)) { goto Exit; } hr = DefaultBinding_ICalculator_Add( proxy, 1, 2, &result, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } wprintf(L"%d + %d = %d\n", 1, 2, result); Exit: if (FAILED(hr)) { // Print out the error PrintError(hr, error); } if (proxy != NULL) { WsCloseServiceProxy( proxy, NULL, NULL); WsFreeServiceProxy( proxy); } if (securityToken != NULL) { WsFreeSecurityToken( securityToken); } if (heap != NULL) { WsFreeHeap(heap); } if (error != NULL) { WsFreeError(error); } fflush(stdout); return SUCCEEDED(hr) ? 0 : -1; }
// Main entry point int __cdecl wmain() { HRESULT hr = S_OK; WS_ERROR* error = NULL; WS_HEAP* heap = NULL; WS_SERVICE_PROXY* proxy = NULL; int result = 0; WS_ENDPOINT_ADDRESS address = {}; static const WS_STRING url= WS_STRING_VALUE(L"http://localhost/example"); address.url = url; // Create an error object for storing rich error information hr = WsCreateError( NULL, 0, &error); if (FAILED(hr)) { goto Exit; } // Create a heap to store deserialized data hr = WsCreateHeap( /*maxSize*/ 2048, /*trimSize*/ 512, NULL, 0, &heap, error); if (FAILED(hr)) { goto Exit; } // In order to use the custom channel through Service Model, // we need to configure it to disable all timeouts. WS_CHANNEL_PROPERTY channelPropertyArray[1]; BOOL enableTimeouts = FALSE; channelPropertyArray[0].id = WS_CHANNEL_PROPERTY_ENABLE_TIMEOUTS; channelPropertyArray[0].value = &enableTimeouts; channelPropertyArray[0].valueSize = sizeof(enableTimeouts); // Set up channel properties for the custom channel WS_CHANNEL_PROPERTY customChannelPropertyArray[2]; // Set up channel property that specifies the callbacks that implement the custom channel customChannelPropertyArray[0].id = WS_CHANNEL_PROPERTY_CUSTOM_CHANNEL_CALLBACKS; customChannelPropertyArray[0].value = &layeredChannelCallbacks; customChannelPropertyArray[0].valueSize = sizeof(layeredChannelCallbacks); // Initialize parameters to pass to the layered channel. // Note that the parameters structure and it's contents must // remain valid until the proxy object has been freed. In this // example, the parameters are declared on the stack for // simplicity, but in other scenarios they may need to be // allocated from the heap. LayeredChannelParameters layeredChannelParameters; layeredChannelParameters.channelBinding = WS_HTTP_CHANNEL_BINDING; layeredChannelParameters.channelProperties = channelPropertyArray; layeredChannelParameters.channelPropertyCount = WsCountOf(channelPropertyArray); layeredChannelParameters.securityDescription = NULL; // Specify the channel parameters as a channel property customChannelPropertyArray[1].id = WS_CHANNEL_PROPERTY_CUSTOM_CHANNEL_PARAMETERS; customChannelPropertyArray[1].value = &layeredChannelParameters; customChannelPropertyArray[1].valueSize = sizeof(layeredChannelParameters); // Create the proxy hr = WsCreateServiceProxy( WS_CHANNEL_TYPE_REQUEST, WS_CUSTOM_CHANNEL_BINDING, NULL, NULL, 0, customChannelPropertyArray, WsCountOf(customChannelPropertyArray), &proxy, error); if (FAILED(hr)) { goto Exit; } hr = WsOpenServiceProxy( proxy, &address, NULL, error); if (FAILED(hr)) { goto Exit; } hr = DefaultBinding_ICalculator_Add( proxy, 1, 2, &result, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } wprintf(L"%d + %d = %d\n", 1, 2, result); Exit: if (FAILED(hr)) { // Print out the error PrintError(hr, error); } if (proxy != NULL) { WsCloseServiceProxy( proxy, NULL, NULL); WsFreeServiceProxy( proxy); } if (heap != NULL) { WsFreeHeap(heap); } if (error != NULL) { WsFreeError(error); } fflush(stdout); return SUCCEEDED(hr) ? 0 : -1; }
// Main entry point int __cdecl wmain() { HRESULT hr = S_OK; WS_ERROR* error = NULL; WS_HEAP* heap = NULL; WS_SERVICE_PROXY* serviceProxy = NULL; int result = 0; WS_ENDPOINT_ADDRESS address = {}; static const WS_STRING url = WS_STRING_VALUE(L"https://localhost:8443/example"); address.url = url; // Create an error object for storing rich error information hr = WsCreateError( NULL, 0, &error); if (FAILED(hr)) { goto Exit; } // Create a heap to store deserialized data hr = WsCreateHeap( /*maxSize*/ 2048, /*trimSize*/ 512, NULL, 0, &heap, error); if (FAILED(hr)) { goto Exit; } // Create the proxy hr = DefaultBinding_ICalculator_CreateServiceProxy( NULL, NULL, 0, &serviceProxy, error); if (FAILED(hr)) { goto Exit; } hr = WsOpenServiceProxy(serviceProxy, &address, NULL, error); if (FAILED(hr)) { goto Exit; } hr = DefaultBinding_ICalculator_Add(serviceProxy, 1, 2, &result, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } wprintf(L"%d + %d = %d\n", 1, 2, result); Exit: if (FAILED(hr)) { // Print out the error PrintError(hr, error); } if (serviceProxy != NULL) { WsCloseServiceProxy(serviceProxy, NULL, NULL); WsFreeServiceProxy(serviceProxy); } if (heap != NULL) { WsFreeHeap(heap); } if (error != NULL) { WsFreeError(error); } fflush(stdout); return SUCCEEDED(hr) ? 0 : -1; }
// Main entry point int __cdecl wmain() { HRESULT hr = S_OK; WS_ERROR* error = NULL; WS_SERVICE_PROXY* serviceProxy = NULL; WS_HEAP* heap = NULL; WS_ENDPOINT_ADDRESS address = {0}; static const WS_STRING serviceUrl = WS_STRING_VALUE(L"http://localhost/example"); address.url = serviceUrl; WS_CALL_PROPERTY callProperties[2]; _OrderSession orderSession; orderSession.sessionId = L"ExampleSession"; WS_PROXY_MESSAGE_CALLBACK_CONTEXT inputMessageContext = {0}; WS_PROXY_MESSAGE_CALLBACK_CONTEXT outputMessageContext = {0}; // Create an error object for storing rich error information hr = WsCreateError( NULL, 0, &error); if (FAILED(hr)) { goto Exit; } // Create a heap to store deserialized data hr = WsCreateHeap( /*maxSize*/ 2048, /*trimSize*/ 512, NULL, 0, &heap, error); if (FAILED(hr)) { goto Exit; } hr = WsCreateServiceProxy( WS_CHANNEL_TYPE_REQUEST, WS_HTTP_CHANNEL_BINDING, NULL, NULL, 0, NULL, 0, &serviceProxy, error); if (FAILED(hr)) { goto Exit; } // Open channel to address hr = WsOpenServiceProxy( serviceProxy, &address, NULL, error); if (FAILED(hr)) { goto Exit; } inputMessageContext.callback = AddSessionHeader; inputMessageContext.state = &orderSession; outputMessageContext.callback = RetrieveSessionHeader; outputMessageContext.state = &orderSession; callProperties[0].id = WS_CALL_PROPERTY_SEND_MESSAGE_CONTEXT; callProperties[0].value = &inputMessageContext; callProperties[0].valueSize = sizeof(inputMessageContext); callProperties[1].id = WS_CALL_PROPERTY_RECEIVE_MESSAGE_CONTEXT; callProperties[1].value = &outputMessageContext; callProperties[1].valueSize = sizeof(outputMessageContext); for (int i = 0; i < 100; i++) { static const WCHAR* productName = L"Pencil"; WCHAR* expectedShipDate = {0}; unsigned int orderID; hr = PurchaseOrderBinding_Order( serviceProxy, 100, (WCHAR*)productName, &orderID, &expectedShipDate, heap, callProperties, WsCountOf(callProperties), NULL, error); if (FAILED(hr)) { goto Exit; } // Print out confirmation contents wprintf(L"Expected ship date for order %lu is %s\n", orderID, expectedShipDate); hr = WsResetHeap(heap, error); if (FAILED(hr)) { goto Exit; } } Exit: if (FAILED(hr)) { // Print out the error PrintError(hr, error); } if (serviceProxy != NULL) { WsCloseServiceProxy(serviceProxy, NULL, NULL); WsFreeServiceProxy(serviceProxy); } if (heap != NULL) { WsFreeHeap(heap); } if (error != NULL) { WsFreeError(error); } fflush(stdout); return SUCCEEDED(hr) ? 0 : -1; }
// Main entry point int __cdecl wmain() { HRESULT hr = S_OK; WS_ERROR* error = NULL; WS_HEAP* heap = NULL; WS_SERVICE_PROXY* serviceProxy = NULL; static const WS_STRING serviceUrl = WS_STRING_VALUE(L"http://localhost/example"); // In this sample, wsutil is used with the /string:WS_STRING command line option // to compile the schema files. When /string:WS_STRING is used, wsutil generates stubs // using WS_STRING (instead of WCHAR*) type for strings. WS_STRING productName; WS_STRING expectedShipDate; WS_STRING orderStatus; WS_ENDPOINT_ADDRESS address = {}; address.url = serviceUrl; // Create an error object for storing rich error information hr = WsCreateError( NULL, 0, &error); if (FAILED(hr)) { goto Exit; } // Create a heap to store deserialized data hr = WsCreateHeap( /*maxSize*/ 2048, /*trimSize*/ 512, NULL, 0, &heap, error); if (FAILED(hr)) { goto Exit; } hr = WsCreateServiceProxy( WS_CHANNEL_TYPE_REQUEST, WS_HTTP_CHANNEL_BINDING, NULL, NULL, 0, NULL, 0, &serviceProxy, error); if (FAILED(hr)) { goto Exit; } hr = WsOpenServiceProxy( serviceProxy, &address, NULL, error); if (FAILED(hr)) { goto Exit; } productName.chars = L"Pencil"; productName.length = 6; for (int i = 0; i < 100; i++) { unsigned int orderID; // Submit an order, and get expected ship date hr = PurchaseOrderBinding_Order( serviceProxy, 100, productName, &orderID, &expectedShipDate, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } // Print out confirmation contents wprintf(L"Expected ship date for order %lu is %.*s\n", orderID, expectedShipDate.length, expectedShipDate.chars); WsResetHeap(heap, NULL); // Get the current status of the order hr = PurchaseOrderBinding_OrderStatus( serviceProxy, &orderID, &orderStatus, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } // Print out order status wprintf(L"Order status for order %lu is: %.*s\n", orderID, orderStatus.length, orderStatus.chars); WsResetHeap( heap, NULL); // Get the current status of the order using an invalid order ID orderID = 321; hr = PurchaseOrderBinding_OrderStatus( serviceProxy, &orderID, &orderStatus, heap, NULL, 0, NULL, error); // Check to see if we got a fault if (hr == WS_E_ENDPOINT_FAULT_RECEIVED) { // Print the strings in the error object PrintError(hr, error); static const WS_XML_STRING _faultDetailName = WS_XML_STRING_VALUE("OrderNotFound"); static const WS_XML_STRING _faultDetailNs = WS_XML_STRING_VALUE("http://example.com"); static const WS_XML_STRING _faultAction = WS_XML_STRING_VALUE("http://example.com/fault"); static const WS_ELEMENT_DESCRIPTION _faultElementDescription = { (WS_XML_STRING*)&_faultDetailName, (WS_XML_STRING*)&_faultDetailNs, WS_UINT32_TYPE, NULL }; static const WS_FAULT_DETAIL_DESCRIPTION orderNotFoundFaultTypeDescription = { (WS_XML_STRING*)&_faultAction, (WS_ELEMENT_DESCRIPTION*)&_faultElementDescription }; // Try to get the fault detail from the error object _OrderNotFoundFaultType* orderNotFound; hr = WsGetFaultErrorDetail( error, &orderNotFoundFaultTypeDescription, WS_READ_OPTIONAL_POINTER, heap, &orderNotFound, sizeof(orderNotFound)); if (FAILED(hr)) { goto Exit; } if (orderNotFound != NULL) { // Print out the fault detail wprintf(L"Order %lu was not found\n", orderNotFound->orderID); } // Reset error so it can be used again hr = WsResetError(error); if (FAILED(hr)) { goto Exit; } } if (FAILED(hr)) { goto Exit; } WsResetHeap(heap, NULL); wprintf(L"\n"); } Exit: if (FAILED(hr)) { // Print out the error PrintError(hr, error); } if (serviceProxy != NULL) { WsCloseServiceProxy(serviceProxy, NULL, NULL); WsFreeServiceProxy(serviceProxy); } if (heap != NULL) { WsFreeHeap(heap); } if (error != NULL) { WsFreeError(error); } fflush(stdout); return SUCCEEDED(hr) ? 0 : -1; }
// Main entry point int __cdecl wmain() { HRESULT hr = S_OK; WS_ERROR* error = NULL; WS_HEAP* heap = NULL; WS_SERVICE_PROXY* proxy = NULL; // declare and initialize a Windows credential WS_STRING_WINDOWS_INTEGRATED_AUTH_CREDENTIAL windowsCredential = {}; // zero out the struct windowsCredential.credential.credentialType = WS_STRING_WINDOWS_INTEGRATED_AUTH_CREDENTIAL_TYPE; // set the credential type // for illustration only; usernames and passwords should never be included in source files windowsCredential.username.chars = L".\\TestUserForBasicAuth"; windowsCredential.username.length = (ULONG)wcslen(windowsCredential.username.chars); windowsCredential.password.chars = L"TstPWD@*4Bsic"; windowsCredential.password.length = (ULONG)wcslen(windowsCredential.password.chars); // declare and initialize properties to set the authentication scheme to Basic ULONG scheme = WS_HTTP_HEADER_AUTH_SCHEME_BASIC; WS_SECURITY_BINDING_PROPERTY httpAuthBindingProperties[1] = { { WS_SECURITY_BINDING_PROPERTY_HTTP_HEADER_AUTH_SCHEME, &scheme, sizeof(scheme) } }; // declare and initialize an HTTP header authentication security binding WS_HTTP_HEADER_AUTH_SECURITY_BINDING httpAuthBinding = {}; // zero out the struct httpAuthBinding.binding.bindingType = WS_HTTP_HEADER_AUTH_SECURITY_BINDING_TYPE; // set the binding type httpAuthBinding.binding.properties = httpAuthBindingProperties; httpAuthBinding.binding.propertyCount = WsCountOf(httpAuthBindingProperties); httpAuthBinding.clientCredential = &windowsCredential.credential; // declare and initialize an SSL transport security binding WS_SSL_TRANSPORT_SECURITY_BINDING sslBinding = {}; // zero out the struct sslBinding.binding.bindingType = WS_SSL_TRANSPORT_SECURITY_BINDING_TYPE; // set the binding type // declare and initialize the array of all security bindings WS_SECURITY_BINDING* securityBindings[2] = { &sslBinding.binding, &httpAuthBinding.binding }; // declare and initialize the security description WS_SECURITY_DESCRIPTION securityDescription = {}; // zero out the struct securityDescription.securityBindings = securityBindings; securityDescription.securityBindingCount = WsCountOf(securityBindings); int result = 0; WS_ENDPOINT_ADDRESS address = {}; static const WS_STRING url = WS_STRING_VALUE(L"https://localhost:8443/example"); address.url = url; // Create an error object for storing rich error information hr = WsCreateError( NULL, 0, &error); if (FAILED(hr)) { goto Exit; } // Create a heap to store deserialized data hr = WsCreateHeap( /*maxSize*/ 2048, /*trimSize*/ 512, NULL, 0, &heap, error); if (FAILED(hr)) { goto Exit; } // Create the proxy hr = WsCreateServiceProxy( WS_CHANNEL_TYPE_REQUEST, WS_HTTP_CHANNEL_BINDING, &securityDescription, NULL, 0, NULL, 0, &proxy, error); if (FAILED(hr)) { goto Exit; } hr = WsOpenServiceProxy( proxy, &address, NULL, error); if (FAILED(hr)) { goto Exit; } hr = DefaultBinding_ICalculator_Add( proxy, 1, 2, &result, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } wprintf(L"%d + %d = %d\n", 1, 2, result); Exit: if (FAILED(hr)) { // Print out the error PrintError(hr, error); } if (proxy != NULL) { WsCloseServiceProxy( proxy, NULL, NULL); WsFreeServiceProxy( proxy); } if (heap != NULL) { WsFreeHeap(heap); } if (error != NULL) { WsFreeError(error); } fflush(stdout); return SUCCEEDED(hr) ? 0 : -1; }
// Main entry point int __cdecl wmain() { HRESULT hr = S_OK; WS_ERROR* error = NULL; WS_SERVICE_PROXY* serviceProxy = NULL; WS_HEAP* heap = NULL; WS_ENDPOINT_ADDRESS address = {}; static const WS_STRING serviceUrl = WS_STRING_VALUE(L"http://terraservice.net/TerraService2.asmx"); WS_CHANNEL_PROPERTY channelPropertyArray[4]; WS_ADDRESSING_VERSION addressingVersion = WS_ADDRESSING_VERSION_TRANSPORT; WS_ENVELOPE_VERSION envelopeVersion = WS_ENVELOPE_VERSION_SOAP_1_1; WCHAR* place = NULL; WS_HTTP_PROXY_SETTING_MODE proxySettingMode = WS_HTTP_PROXY_SETTING_MODE_CUSTOM; WS_CUSTOM_HTTP_PROXY customProxy = {}; address.url = serviceUrl; WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions = {}; WINHTTP_PROXY_INFO proxyInfo = {}; HINTERNET session = NULL; channelPropertyArray[0].id = WS_CHANNEL_PROPERTY_ADDRESSING_VERSION; channelPropertyArray[0].value = &addressingVersion; channelPropertyArray[0].valueSize = sizeof(addressingVersion); channelPropertyArray[1].id = WS_CHANNEL_PROPERTY_ENVELOPE_VERSION; channelPropertyArray[1].value = &envelopeVersion; channelPropertyArray[1].valueSize = sizeof(envelopeVersion); channelPropertyArray[2].id = WS_CHANNEL_PROPERTY_HTTP_PROXY_SETTING_MODE; channelPropertyArray[2].value = &proxySettingMode; channelPropertyArray[2].valueSize = sizeof(proxySettingMode); channelPropertyArray[3].id = WS_CHANNEL_PROPERTY_CUSTOM_HTTP_PROXY; channelPropertyArray[3].value = &customProxy; channelPropertyArray[3].valueSize = sizeof(customProxy); // This part illustrates how to setup a HTTP header authentication security binding // against the HTTP proxy server in case it requires authentication. // declare and initialize a default windows credential WS_STRING_WINDOWS_INTEGRATED_AUTH_CREDENTIAL windowsCredential = {}; // zero out the struct windowsCredential.credential.credentialType = WS_STRING_WINDOWS_INTEGRATED_AUTH_CREDENTIAL_TYPE; // set the credential type // for illustration only; usernames and passwords should never be included in source files windowsCredential.username.chars = L"domain\\user"; windowsCredential.username.length = (ULONG)wcslen(windowsCredential.username.chars); windowsCredential.password.chars = L"password"; windowsCredential.password.length = (ULONG)wcslen(windowsCredential.password.chars); // declare and initialize properties to set the authentication scheme to Basic ULONG scheme = WS_HTTP_HEADER_AUTH_SCHEME_NEGOTIATE; ULONG target = WS_HTTP_HEADER_AUTH_TARGET_PROXY; WS_SECURITY_BINDING_PROPERTY httpProxyAuthBindingProperties[2] = { { WS_SECURITY_BINDING_PROPERTY_HTTP_HEADER_AUTH_SCHEME, &scheme, sizeof(scheme) }, { WS_SECURITY_BINDING_PROPERTY_HTTP_HEADER_AUTH_TARGET, &target, sizeof(target) } }; // declare and initialize an HTTP header authentication security binding for the HTTP proxy server WS_HTTP_HEADER_AUTH_SECURITY_BINDING httpProxyAuthBinding = {}; // zero out the struct httpProxyAuthBinding.binding.bindingType = WS_HTTP_HEADER_AUTH_SECURITY_BINDING_TYPE; // set the binding type httpProxyAuthBinding.binding.properties = httpProxyAuthBindingProperties; httpProxyAuthBinding.binding.propertyCount = WsCountOf(httpProxyAuthBindingProperties); httpProxyAuthBinding.clientCredential = &windowsCredential.credential; // declare and initialize the array of all security bindings WS_SECURITY_BINDING* securityBindings[1] = { &httpProxyAuthBinding.binding }; // declare and initialize the security description WS_SECURITY_DESCRIPTION securityDescription = {}; // zero out the struct securityDescription.securityBindings = securityBindings; securityDescription.securityBindingCount = WsCountOf(securityBindings); // Create an error object for storing rich error information hr = WsCreateError( NULL, 0, &error); if (FAILED(hr)) { goto Exit; } // Create a heap to store deserialized data hr = WsCreateHeap( /*maxSize*/ 2048, /*trimSize*/ 512, NULL, 0, &heap, error); if (FAILED(hr)) { goto Exit; } session = WinHttpOpen(L"NWS Example", WINHTTP_ACCESS_TYPE_NO_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, WINHTTP_FLAG_ASYNC); if (!session) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Exit; } autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_RUN_INPROCESS | WINHTTP_AUTOPROXY_AUTO_DETECT; autoProxyOptions.dwAutoDetectFlags = WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A; autoProxyOptions.fAutoLogonIfChallenged = FALSE; WinHttpGetProxyForUrl( session, serviceUrl.chars, &autoProxyOptions, &proxyInfo); if (proxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY) { if (proxyInfo.lpszProxy) { customProxy.servers.chars = proxyInfo.lpszProxy; customProxy.servers.length = (ULONG)wcslen(proxyInfo.lpszProxy); } if (proxyInfo.lpszProxyBypass) { customProxy.bypass.chars = proxyInfo.lpszProxyBypass; customProxy.bypass.length = (ULONG)wcslen(proxyInfo.lpszProxyBypass); } } hr = WsCreateServiceProxy( WS_CHANNEL_TYPE_REQUEST, WS_HTTP_CHANNEL_BINDING, &securityDescription, NULL, 0, channelPropertyArray, WsCountOf(channelPropertyArray), &serviceProxy, error); if (FAILED(hr)) { goto Exit; } // Open channel to address hr = WsOpenServiceProxy( serviceProxy, &address, NULL, error); if (FAILED(hr)) { goto Exit; } for (int i = 0; i < 100; i++) { LonLatPt point = {10.0, 10.0}; hr = TerraServiceSoap_ConvertLonLatPtToNearestPlace( serviceProxy, &point, &place, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } if (place != NULL) { wprintf(L"Place @ Lattitude=%f, Longitutde=%f is %s\n", point.Lon, point.Lat, place); } else { wprintf(L"Could not find any place for Lattitude=%f, Longitutde=%f\n", point.Lon, point.Lat); } fflush(stdout); hr = WsResetHeap( heap, error); if (FAILED(hr)) { goto Exit; } } Exit: if (FAILED(hr)) { // Print out the error PrintError(hr, error); } if (proxyInfo.lpszProxy) { ::GlobalFree(proxyInfo.lpszProxy); } if (proxyInfo.lpszProxyBypass) { ::GlobalFree(proxyInfo.lpszProxyBypass); } if (serviceProxy != NULL) { WsCloseServiceProxy(serviceProxy, NULL, NULL); WsFreeServiceProxy(serviceProxy); } if (!session) { WinHttpCloseHandle(session); } if (heap != NULL) { WsFreeHeap(heap); } if (error != NULL) { WsFreeError(error); } fflush(stdout); return SUCCEEDED(hr) ? 0 : -1; }
// Main entry point int __cdecl wmain() { HRESULT hr = S_OK; WS_ERROR* error = NULL; WS_HEAP* heap = NULL; WS_SERVICE_PROXY* serviceProxy = NULL; WS_ENDPOINT_ADDRESS address = {}; const WS_ASYNC_CONTEXT asyncContext = {BlockMethodComplete, NULL}; static const WS_STRING serviceUrl = WS_STRING_VALUE(L"net.tcp://localhost/example"); // Create an error object for storing rich error information hr = WsCreateError( NULL, 0, &error); if (FAILED(hr)) { goto Exit; } // Create a heap to store deserialized data hr = WsCreateHeap( /*maxSize*/ 2048, /*trimSize*/ 512, NULL, 0, &heap, error); if (FAILED(hr)) { goto Exit; } hr = WsCreateServiceProxy(WS_CHANNEL_TYPE_DUPLEX_SESSION, WS_TCP_CHANNEL_BINDING, NULL, NULL, 0, NULL, 0, &serviceProxy, error); if (FAILED(hr)) { goto Exit; } // Initialize address of service address.url = serviceUrl; hr = WsOpenServiceProxy(serviceProxy, &address, NULL, error); if (FAILED(hr)) { goto Exit; } wprintf(L"Calling blocking method async\n"); hr = BlockServiceBinding_Block(serviceProxy, heap, NULL, 0, &asyncContext, error); if (FAILED(hr)) { goto Exit; } wprintf(L"Waiting...\n"); Sleep(5000L); wprintf(L"Now aborting service proxy\n"); hr = WsAbortServiceProxy(serviceProxy, error); if (FAILED(hr)) { goto Exit; } Exit: if (FAILED(hr)) { // Print out the error PrintError(hr, error); } if (serviceProxy != NULL) { WsCloseServiceProxy(serviceProxy, NULL, NULL); WsFreeServiceProxy(serviceProxy); } if (heap != NULL) { WsFreeHeap(heap); } if (error != NULL) { WsFreeError(error); } fflush(stdout); return SUCCEEDED(hr) ? 0 : -1; }
// Main entry point int __cdecl wmain() { HRESULT hr = S_OK; WS_ERROR* error = NULL; WS_HEAP* heap = NULL; WS_SERVICE_PROXY* proxy = NULL; // declare and initialize a username credential WS_STRING_USERNAME_CREDENTIAL usernameCredential = {}; // zero out the struct static const WS_STRING userName = WS_STRING_VALUE(L"usr1"); static const WS_STRING passWord = WS_STRING_VALUE(L"pwd1"); usernameCredential.credential.credentialType = WS_STRING_USERNAME_CREDENTIAL_TYPE; // set the credential type usernameCredential.username = userName; usernameCredential.password = passWord; // declare and initialize a username message security binding WS_USERNAME_MESSAGE_SECURITY_BINDING usernameBinding = {}; // zero out the struct usernameBinding.binding.bindingType = WS_USERNAME_MESSAGE_SECURITY_BINDING_TYPE; // set the binding type usernameBinding.bindingUsage = WS_SUPPORTING_MESSAGE_SECURITY_USAGE; // set the binding usage usernameBinding.clientCredential = &usernameCredential.credential; // declare and initialize an SSL transport security binding WS_SSL_TRANSPORT_SECURITY_BINDING sslBinding = {}; // zero out the struct sslBinding.binding.bindingType = WS_SSL_TRANSPORT_SECURITY_BINDING_TYPE; // set the binding type // declare and initialize the array of all security bindings WS_SECURITY_BINDING* securityBindings[2] = { &sslBinding.binding, &usernameBinding.binding }; // declare and initialize the security description WS_SECURITY_DESCRIPTION securityDescription = {}; // zero out the struct securityDescription.securityBindings = securityBindings; securityDescription.securityBindingCount = WsCountOf(securityBindings); int result = 0; WS_ENDPOINT_ADDRESS address = {}; static const WS_STRING url = WS_STRING_VALUE(L"https://localhost:8443/example"); address.url = url; // Create an error object for storing rich error information hr = WsCreateError( NULL, 0, &error); if (FAILED(hr)) { goto Exit; } // Create a heap to store deserialized data hr = WsCreateHeap( /*maxSize*/ 2048, /*trimSize*/ 512, NULL, 0, &heap, error); if (FAILED(hr)) { goto Exit; } // Create the proxy hr = WsCreateServiceProxy( WS_CHANNEL_TYPE_REQUEST, WS_HTTP_CHANNEL_BINDING, &securityDescription, NULL, 0, NULL, 0, &proxy, error); if (FAILED(hr)) { goto Exit; } hr = WsOpenServiceProxy( proxy, &address, NULL, error); if (FAILED(hr)) { goto Exit; } hr = DefaultBinding_ICalculator_Add( proxy, 1, 2, &result, heap, NULL, 0, NULL, error); if (FAILED(hr)) { goto Exit; } wprintf(L"%d + %d = %d\n", 1, 2, result); Exit: if (FAILED(hr)) { // Print out the error PrintError(hr, error); } if (proxy != NULL) { WsCloseServiceProxy( proxy, NULL, NULL); WsFreeServiceProxy( proxy); } if (heap != NULL) { WsFreeHeap(heap); } if (error != NULL) { WsFreeError(error); } fflush(stdout); return SUCCEEDED(hr) ? 0 : -1; }