0

I am consuming a wsdl described as :

<wsdl:binding name="PassengerConformance_v1Binding"
    type="tns:PassengerConformanceAuthenticationPortType">
    <soap:binding style="document"
        transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="identify">
    </wsdl:operation>
</wsdl:binding>

But the request getting generated is UTF16, which the server wants to be utf-8 This is how my code looks

 var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport)
 {
     Security = new BasicHttpSecurity
     {
         Mode = BasicHttpSecurityMode.Transport,
         Transport = new HttpTransportSecurity
         {
             ClientCredentialType = HttpClientCredentialType.Digest
         }
     }
 };     
 var address = new EndpointAddress(dcsServiceConfiguration.Url);     
 var channel = new ChannelFactory<T>(binding, address);     
 channel.Credentials.HttpDigest.ClientCredential =
      new NetworkCredential(username, Password);     
 var buildDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
 var filePath = buildDir + @"\ClientCert.pfx";     
 channel.Credentials.ClientCertificate.Certificate =
     new X509Certificate2(filePath, "password", X509KeyStorageFlags.MachineKeySet);  

 binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;     
 return channel;

I understand that BasicHttpBinding deafult textEncoding value is utf-8, but still when I check in the message inspector, it comes to be utf-16.

I noticed that when I replicated this code in .net 7.2 framework consoel app, there was no xml tag. which would still work for me Please help.

  • What errors do you got when you consume the service by using ChannelFacotory? Have you tried to invoke the service by adding service reference with Microsoft WCF Web Service Reference Provider? Besides, as far as I know, except we should establish the trust relationship between the server and the client, when we use Basichttpbinding to authenticate the client with a certificate, we need to set the default Certificate (service certificate) additionally. client.ClientCredentials.ServiceCertificate.SetDefaultCertificate – Abraham Qian Jun 27 '19 at 09:12
  • The handshake is successful. it is when i call the operation, the request is built with UTF-16 with response as env:Client Internal Error – kriti gupta Jun 27 '19 at 10:20
  • The generated request when copied to soapui project and I change the encoding to utf-8 , it works. – kriti gupta Jun 27 '19 at 10:29
  • What are the details of the error when you consume the service by using ChannelFactory? Have you tried to invoke the service by adding service reference with Microsoft WCF Web Service Reference Provider? – Abraham Qian Jun 28 '19 at 03:20
  • Using preview for .net core 3 helped resolve the issue. – kriti gupta Sep 11 '19 at 06:38

0 Answers0