Error sending information to WebService: System.ServiceModel.Security.MessageSecurityException

0

I created a simple web service that makes a sum of two numbers and returns the result. The IIS I have configured windows authentication enabled and the others disabled.

Code:

  ServiceReference2.TesteSomaSoapClient a = new ServiceReference2.TesteSomaSoapClient();
  a.ClientCredentials.UserName.UserName = @ "Dominio\user";
  a.ClientCredentials.UserName.Password = "senha";

  var b = a.Soma(1, 1);

You have given me the error:

  An unhandled exception of type 'System.ServiceModel.Security.MessageSecurityException' occurred in mscorlib.dll

     

Additional information: The HTTP request is not authorized in the 'Anonymous' client authentication scheme. The authentication header received from the server was 'Negotiate, NTLM'.

One more detail, I will not be able to send the user and password. Would you like to catch the current user of who is calling the web service?

    
asked by anonymous 12.12.2017 / 15:38

2 answers

0

I've got people

        BasicHttpBinding basicHttpBinding = new BasicHttpBinding();

        basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;

        basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;

        EndpointAddress endpoint = new EndpointAddress("http://localhost:81/GravaSolicitacao.asmx");

        ServiceReference2.GravaSolicitacaoSoapClient client = new ServiceReference2.GravaSolicitacaoSoapClient(basicHttpBinding, endpoint);

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

        client.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;

        //var xx = client.Soma(4, 3);
        var xx = client.GravaSolic(1, 1, 2);
    
14.12.2017 / 13:16
0

is still not working. When I run the way I mentioned in the solution it only works on the machine that you are in. When I call another machine the error occurs:

ERROR: Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.

the machine that is calling the webservice is not able to pass the user that will be used in sql ... has anyone ever been through this?

    
15.12.2017 / 16:37