This blog is about developing Windows applications using Visual Studio. All postings on this weblog are provided "AS IS" with no warranties, and confer no rights. Use of any samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm
Your host Nikola Dudar is a Program Manager in Windows division of Microsoft Corporation. He has been working on Windows Web Services API during Windows 7 and various additions to Visual C++ during VS2005 and VS2008. More details are in LinkedIn profile under Nikola's formal name Mykola Dudar.
If you are interested in program management and project management, check out my other blog at http://www.pmsnack.com/ where I collect best practices and other topics interesting to program and project managers.
To send feedback, comments or requests for new posts, please use the contact form.
I have seen several questions about how to fill out a binding template for CreateServiceProxy(). Here are two examples which I believe should help you with this task.
In the first example, I increase the size of messages allowed for the client to send to the service. To do that the code changes the corresponding channel property for a channel that the Service Proxy is going to use.
// defining the desirable maximum size for messages ULONG maxMessageSize = 2147483647; //changing a channel property WS_CHANNEL_PROPERTY channelProperty[1]; channelProperty[0].id = WS_CHANNEL_PROPERTY_MAX_BUFFERED_MESSAGE_SIZE; channelProperty[0].value = &maxMessageSize; channelProperty[0].valueSize = sizeof(maxMessageSize); WS_CHANNEL_PROPERTIES channelProperties; channelProperties.properties = channelProperty; channelProperties.propertyCount = 1; // filling in out the template with the new channel property WS_HTTP_BINDING_TEMPLATE templateValue = {}; templateValue.channelProperties = channelProperties; // creating Service Proxy using the changed binding template hr = WSHttpBinding_IArraySort_CreateServiceProxy(&templateValue, NULL, 0, &serviceProxy, error);
// defining the desirable maximum size for messages ULONG maxMessageSize = 2147483647;
//changing a channel property WS_CHANNEL_PROPERTY channelProperty[1]; channelProperty[0].id = WS_CHANNEL_PROPERTY_MAX_BUFFERED_MESSAGE_SIZE; channelProperty[0].value = &maxMessageSize; channelProperty[0].valueSize = sizeof(maxMessageSize); WS_CHANNEL_PROPERTIES channelProperties; channelProperties.properties = channelProperty; channelProperties.propertyCount = 1;
// filling in out the template with the new channel property WS_HTTP_BINDING_TEMPLATE templateValue = {}; templateValue.channelProperties = channelProperties;
// creating Service Proxy using the changed binding template hr = WSHttpBinding_IArraySort_CreateServiceProxy(&templateValue, NULL, 0, &serviceProxy, error);
In the second example, we provide a username and a password from the client to the service. We start from creating a User Credential structure that later on passed to the binding template. Username and password will be send to the service on a call to its operation.
// declare and initialize a username credential WS_STRING_USERNAME_CREDENTIAL usernameCredential = {}; usernameCredential.credential.credentialType = WS_STRING_USERNAME_CREDENTIAL_TYPE; usernameCredential.username.chars = username; usernameCredential.username.length = wcslen(username); usernameCredential.password.chars = password; usernameCredential.password.length = wcslen(password); // declare and initialize a username message security binding WS_HTTP_SSL_USERNAME_SECURITY_CONTEXT_BINDING_TEMPLATE templateValue = {}; templateValue.usernameMessageSecurityBinding.clientCredential = &usernameCredential.credential; // Creating Service Proxy using template fucntion generated from the metadata hr = WSHttpBinding_ICalculator_CreateServiceProxy( &templateValue, NULL, 0, &serviceProxy, error);
// declare and initialize a username credential WS_STRING_USERNAME_CREDENTIAL usernameCredential = {}; usernameCredential.credential.credentialType = WS_STRING_USERNAME_CREDENTIAL_TYPE; usernameCredential.username.chars = username; usernameCredential.username.length = wcslen(username); usernameCredential.password.chars = password; usernameCredential.password.length = wcslen(password); // declare and initialize a username message security binding WS_HTTP_SSL_USERNAME_SECURITY_CONTEXT_BINDING_TEMPLATE templateValue = {}; templateValue.usernameMessageSecurityBinding.clientCredential = &usernameCredential.credential;
// Creating Service Proxy using template fucntion generated from the metadata hr = WSHttpBinding_ICalculator_CreateServiceProxy( &templateValue, NULL, 0, &serviceProxy, error);
These two examples demonstrate the general approach. There are 13 binding templates in the API listed here. They all can be filled in using the similar approach. Give it a try and if you have questions just post them as comments to this post.
PingBack from http://blog.a-foton.ru/index.php/2009/03/20/filling-out-binding-template-for-createserviceproxy-call/