Using WCF and WebProxy getting System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was ''. ---> System.Net.WebException: RRS feed

  • Question

  • I have a VS2013 Windows desktop app using target framework .NET Framework 4.5 which uses WCF to communicate with a Java server

    It uses custom binding to do this and it also works using a static WebProxy provided that the Proxy Server is defined in IE11's Proxy Server LAN settings.

    If a user and password are required to connect via the static proxy then my code currently works doing something like

    Dim proxyCredentials As System.Net.NetworkCredential = Nothing
    proxyCredentials = New System.Net.NetworkCredential(AuthenticatedProxyUser, AuthenticatedProxyPassword)
    WebRequest.DefaultWebProxy.Credentials = proxyCredentials

    A Customer has asked me to make it work without having to define the proxy server address and port in LAN Settings but so far I have been unable to do this. Is it possible?

    In theory I should just be able to do something like

                    Dim proxy As WebProxy = New WebProxy(AuthenticatedProxyAddress)
                    proxy.Credentials = proxyCredentials
                    WebRequest.DefaultWebProxy = proxy

    But the response I get is

    The HTTP request is unauthorized with client authentication scheme 'Anonymous'. 
    The authentication header received from the server was ''. 
    ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.

    • Moved by Alex-KSGZ Friday, August 30, 2019 1:04 AM
    Thursday, August 29, 2019 10:50 AM

All replies

  • You should post to the MSDN WCF  forum  for help.
    Thursday, August 29, 2019 11:41 AM
  • Thanks I'll try there
    Thursday, August 29, 2019 12:43 PM
  • Hello,

    There is a good post here on this topic


    Then look at


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Thursday, August 29, 2019 1:47 PM
  • Hi Karen,

    I agree those posts look promising (I've in fact seen them already).

    I've tried changing

    proxy.ClientCredentials.Windows.AllowedImpersonationLevel =   

    but it didn't fix it.

    I'm using custom binding with

            Dim binding As New CustomBinding
            Dim securityElement As SecurityBindingElement
            securityElement = New TransportSecurityBindingElement
            securityElement.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12
            securityElement.EnableUnsecuredResponse = True
            securityElement.IncludeTimestamp = True

            Dim customHttps As New ThCustomHttpsTransportBindingElement(ThWebServices.AuthenticatedProxyAddress)

    ThCustomHttpsTransportBindingElement inherits HttpsTransportBindingElement and lets me set MaxReceivedMessageSize

    How do I do this

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

    in code?


    Thursday, August 29, 2019 2:50 PM