2

We are using SDL Web 8.5. Trying to create a custom application which will get all PDF component and download them inside a specific location while trying to download pdf file from corresponding multimedia component I'm getting this error:

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

I am using below code to initialize StreamDownloadClient

BasicHttpBinding basicHttpBinding = new BasicHttpBinding
           {
               MaxReceivedMessageSize = 10485760,
               ReaderQuotas = new XmlDictionaryReaderQuotas
               {
                   MaxStringContentLength = 10485760,
                   MaxArrayLength = 10485760
               },
               MessageEncoding = WSMessageEncoding.Mtom,
               Security = new BasicHttpSecurity
               {
                   Mode = BasicHttpSecurityMode.None,
               }
           };

           var remoteAddress = new EndpointAddress("http://xxx.xxx.xxx.xxx/webservices/CoreService2013.svc/streamDownload_basicHttp");

           StreamDownloadClient streamDownloadClient = new StreamDownloadClient(basicHttpBinding, remoteAddress);
           return streamDownloadClient;

2 Answers 2

3

Although Velu's code is OK, it doesn't explain what is the issue and how to solve it. What you have as an issue, is basic issue with Web Service Client configuration. As you can see from this page, this one, and this one, the issue is that you don't specify AllowNtlm = true which Velu does in this line:

client.ChannelFactory.Credentials.Windows.AllowNtlm = true;

The other option is to set this not in code, but in config section related to your binding like this:

<security mode="TransportCredentialOnly">
  <transport clientCredentialType="Ntlm" proxyCredentialType="None"realm="" />
  <message clientCredentialType="UserName" algorithmSuite="Default" />
</security>

What it basically means? Well, your client configuration needs to match credential types specified by Server.

2
  • your genious :) Commented Apr 30, 2019 at 17:37
  • hhahhaha thanks :D
    – Marko Milic
    Commented Apr 30, 2019 at 18:39
1

Try this code sample:

    static StreamDownloadClient GetStreamDownloadClient(string hostname, string username, string password)
    {
        var basicHttpBinding = new BasicHttpBinding
        {
            MaxBufferSize = 10485760, // 4MB
            MaxBufferPoolSize = 10485760,
            MaxReceivedMessageSize = 10485760,
            MessageEncoding = WSMessageEncoding.Mtom,
            TransferMode = TransferMode.StreamedResponse,
            Security = new BasicHttpSecurity
            {
                Mode = BasicHttpSecurityMode.TransportCredentialOnly,
                Transport = new HttpTransportSecurity
                {
                    ClientCredentialType = HttpClientCredentialType.Windows
                }
            }
        };

        hostname = string.Format("{0}{1}{2}", hostname.StartsWith("http") ? "" : "http://", hostname, hostname.EndsWith("/") ? "" : "/");
        var endpoint = new EndpointAddress(hostname + "webservices/CoreService201603.svc/streamDownload_basicHttp");
        StreamDownloadClient client = new StreamDownloadClient(basicHttpBinding, endpoint);
        client.ChannelFactory.Credentials.Windows.ClientCredential = new NetworkCredential(username, password);
        client.ChannelFactory.Credentials.Windows.AllowNtlm = true;
        return client;
    }

I hope it helps.

1
  • Thanks Velmurugan it works Commented Apr 30, 2019 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.