title: How to connect to a WCF service with Custom Binding from unmanaged C++
body: <p>I need to connect to a WCF service from a native C++ application. I tried the link below and it worked with <code>wsHttpBinding</code>.  </p>
  
  <p><a href="https://stackoverflow.com/questions/686452/create-wcf-service-for-unmanaged-c-clients">Create WCF service for unmanaged C++ clients</a>  </p>
  
  <p>However I need to connect to a WCF service with a custom binding. This is how the code for the Custom Binding looks like in my app config file  </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
    &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;customBinding&gt;
          &lt;binding name="ResourceCenterEndpoint5"&gt;
            &lt;mtomMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
              messageVersion="Default" maxBufferSize="65536" writeEncoding="utf-8"&gt;
              &lt;readerQuotas maxDepth="32" maxStringContentLength="8192"      maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
            &lt;/mtomMessageEncoding&gt;
            &lt;httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                      maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Ntlm"
                      bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                      keepAliveEnabled="true" maxBufferSize="65536"
                      proxyAuthenticationScheme="Anonymous"
                      realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                      useDefaultWebProxy="true" /&gt;
          &lt;/binding&gt;
        &lt;/customBinding&gt;
        &lt;/binding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
        &lt;endpoint address="http://usaabcxyzas1.na.abc.com/Build15/ReserSVC/Resource.svc"
        binding="customBinding" bindingConfiguration="ResourceCenterEndpoint5"
        contract="ServiceReference2.ResourceCenterServiceContract"
        name="ResourceCenterEndpoint5"&gt;
          &lt;identity&gt;
            &lt;userPrincipalName value="devlts_srv@na.abc.com" /&gt;
          &lt;/identity&gt;
        &lt;/endpoint&gt;
      &lt;/client&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I have a bridge DLL which is a managed C++ DLL. The managed C++ DLL connects the C# Client to the native appliaction. However I am unable to connect to the Web Service from the managed C++ DLL as the web service is using custom binding. The error I get is:  </p>
  
  <blockquote>
    <p>The http request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the sever was 'Negotiate,NTLM'</p>
  </blockquote>
  
  <p>This is how I tried to connect to the Webservice from the manged C++ dll:</p>
  
  <pre><code>Binding^ binding = gcnew BasicHttpBinding();
  
  EndpointAddress^ address = gcnew EndpointAddress(gcnew String("http://usaabcxyzas1.na.abc.com/Build15/ReserSVC/Resource.svc"));
  
  HelloServiceClient::ServiceReference2::ResourceCenterServiceContractClient^ client = gcnew HelloServiceClient::ServiceReference2::ResourceCenterServiceContractClient(binding, address); 
  client-&gt;DoWork();
  </code></pre>
  
  <p>So basically I need to connect the managed C++ dll to the WCF Service with custom binding. How can I do this?</p>