0

I'm trying to call a method for a web service we use. I keep getting this error

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate, NTLM'.

The reference file shows that the class is a sub class of ClientBase.

I'm able to see the Web.Config file but not manipulate it. This is what it shows for binding.

    <bindings>
  <basicHttpBinding>
    <binding name="basicHttpBindingWinAuthConf" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="32" maxStringContentLength="2000000000" maxArrayLength="2000000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="Transport">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="webHttpBindingConf">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </webHttpBinding>
  <customBinding>
    <binding name="binaryHttpBindingSecuredFalse" maxSessionSize="2000000000">
      <binaryMessageEncoding>
        <readerQuotas maxDepth="32" maxStringContentLength="2000000000" maxArrayLength="2000000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      </binaryMessageEncoding>
      <httpTransport maxReceivedMessageSize="2000000000" transferMode="StreamedResponse" authenticationScheme="Negotiate" />
    </binding>
    <binding name="binaryHttpBindingSecuredTrue" maxSessionSize="2000000000">
      <binaryMessageEncoding>
        <readerQuotas maxDepth="32" maxStringContentLength="2000000000" maxArrayLength="2000000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      </binaryMessageEncoding>
      <httpsTransport maxReceivedMessageSize="2000000000" transferMode="StreamedResponse" authenticationScheme="Negotiate" />
    </binding>
    <binding name="binaryHttpBindingSecured" maxSessionSize="2000000000">
      <binaryMessageEncoding>
        <readerQuotas maxDepth="32" maxStringContentLength="2000000000" maxArrayLength="2000000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      </binaryMessageEncoding>
      <httpsTransport maxReceivedMessageSize="2000000000" transferMode="StreamedResponse" authenticationScheme="Negotiate" />
    </binding>
    <binding name="binaryHttpBinding" maxSessionSize="2000000000">
      <binaryMessageEncoding>
        <readerQuotas maxDepth="32" maxStringContentLength="2000000000" maxArrayLength="2000000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      </binaryMessageEncoding>
      <httpTransport maxReceivedMessageSize="2000000000" transferMode="StreamedResponse" authenticationScheme="Negotiate" />
    </binding>
  </customBinding>
</bindings>

I've tried the code below to authorize my call

       BasicHttpBinding bind = new BasicHttpBinding();
   bind.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
   bind.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
   EndpointAddress endpoint = new EndpointAddress("http://uri_to_service/transactionservices.asmx");

Before the update I would use this line of code and it worked as it should

 TS.Credentials = System.Net.CredentialCache.DefaultCredentials;

What am I doing wrong?

UPDATE

I've also tried this and had no luck...

            TS.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; 
        TS.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;

Some have suggested this but did not work....

TS.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; 

looking into the web config file I saw this so I don't it would work anyways..

<authentication mode="Windows" />
<identity impersonate="false" />

Any ideas?

Mmedi005
  • 35
  • 7
  • `Before the update` what update? Did you switch from .NET Framework to .NET Core? .NET 5 and .NET 6 are actually .NET *Core* versions. – Panagiotis Kanavos Jan 11 '22 at 15:26
  • The company that created the service updated it where the code that worked before no longer has Credentials as a property to set. Looks like they rewrote the class and how it connects to them. The pacakges.config file targetFramework is net462 – Mmedi005 Jan 11 '22 at 15:42
  • Maybe you can check [this thread](https://stackoverflow.com/questions/1044034/wcftestclient-the-http-request-is-unauthorized-with-client-authentication-scheme) and [this doc](https://learn.microsoft.com/en-us/troubleshoot/developer/webapps/iis/www-authentication-authorization/access-denied-call-web-service) to find a solution. – Lan Huang Jan 12 '22 at 08:22
  • I've read through this thread before and no luck. The doc shows examples of how I was able to set Credentials before but now Credentials property is longer available to set. – Mmedi005 Jan 12 '22 at 14:37
  • you can look at [this](https://learn.microsoft.com/en-us/previous-versions/msp-n-p/ff648505(v=pandp.10)?redirectedfrom=MSDN). – Lan Huang Jan 13 '22 at 09:22
  • My app is written in net core 3.1 and looks like connecting to web reference (SOAP) written in target framework 4.6.1.....net core does not have the same references so I get errors trying to reference it. I've used the tool svcutil.exe and I get this error Warning: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter Error: Referenced type 'http://schemas.xmlsoap.org/soap/encoding/:Array' is only valid for encoded SOAP. – Mmedi005 Jan 13 '22 at 18:44
  • Also why does 4.6.1 create a reference with no problem and core gets a bunch of errors and does not give the same references? – Mmedi005 Jan 14 '22 at 14:41
  • Because .net core does not support WCF full functionality https://stackoverflow.com/questions/48522849/what-replaces-wcf-in-net-core – Lan Huang Jan 18 '22 at 09:04

0 Answers0