Skip to content

Instantly share code, notes, and snippets.

@Krizzzn
Created July 17, 2012 07:33
Show Gist options
  • Save Krizzzn/3127827 to your computer and use it in GitHub Desktop.
Save Krizzzn/3127827 to your computer and use it in GitHub Desktop.
C# - accessing service reference with the headers Negotiate, Ntlm
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="NintexWorkflowWSSoap" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://intranet.aDomain.net/_vti_bin/nintexworkflow/workflow.asmx"
binding="basicHttpBinding" bindingConfiguration="NintexWorkflowWSSoap"
contract="Nintex.Service.NintexWorkflowWSSoap" name="NintexWorkflowWSSoap" />
</client>
</system.serviceModel>
</configuration>

this gist solves the MessageSecurityException "The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'Negotiate,NTLM'.".

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;
using System.ServiceModel;
namespace TheTestConsole
{
class Program
{
static void Main(string[] args)
{
var client = new Nintex.Service.NintexWorkflowWSSoapClient("NintexWorkflowWSSoap");
client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
client.ClientCredentials.Windows.AllowNtlm = true;
client.ClientCredentials.Windows.ClientCredential.Domain = "aDomain";
client.ClientCredentials.Windows.ClientCredential.UserName = "aName";
client.ClientCredentials.Windows.ClientCredential.Password = "*********";
var result = client.PublishFromNWFXml(m, "Request List", "Approval", false);
}
}
}
@Krizzzn
Copy link
Author

Krizzzn commented Jul 17, 2012

this gist solves the MessageSecurityException "The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'Negotiate,NTLM'.".

@contrequarte
Copy link

Thank you very much!!! This gist saved me lots of time!

@mbratukha
Copy link

AllowNtlm = true is deprecated. My solution is to set NTLM in clientCredentialType in app.config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment