Security Wcf Authentication Username c #

0

I'm doing a web service with WCF of c # good when I run the service it appears like this

and does not ask for any validation or authentication.

I would like to put an authentication when you consume that service requires to request a username and password.

since this service will be consumed by an external one, and if it does not have a security any will consume my service.

I would like that when they consume the external ones, if it is the same, the user and key consume and if they do not know that they do not consume

if you could help me.

This is my webconfig code:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
    <authentication mode="Forms">
      <forms name="401kApp" loginUrl="/Service1.svc">
        <credentials passwordFormat = "SHA1">

          <user name="UserName1" password="SHA1EncryptedPassword1"/>
        </credentials>
      </forms>
    </authentication>
  </system.web>
  <connectionStrings>

    <add name="CnxUsu" connectionString="wZhyFoK5oBVv3J+J8qRkKIaRggbvPeaMVBpHLf9B1rGNbBU9aUiRfcuxECM078XGyeTfTUN+tk1gpSSUdPdjAc2alNIzOLufj27DOwCocr5S9fUXOfpyl7dXuw2D9U/4NPLP+zcFs5MoMDY8hrRuZA=="/>

  </connectionStrings>
  <system.serviceModel>

    <bindings>
      <wsHttpBinding>
        <binding name="securitySession">
          <security mode="Message">
            <message clientCredentialType="UserName" establishSecurityContext="true" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>

      <serviceBehaviors>

        <behavior>

          <!-- Para evitar revelar información de los metadatos, establezca los valores siguientes en false antes de la implementación -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- Para recibir detalles de las excepciones en los fallos, con el fin de poder realizar la depuración, establezca el valor siguiente en true. Para no revelar información sobre las excepciones, establézcalo en false antes de la implementación -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>

      </serviceBehaviors>

    </behaviors>

    <protocolMapping>

        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>

    <directoryBrowse enabled="true"/>

  </system.webServer>


</configuration>

This is my code in .cs

[ServiceContract]
    public interface IService1
    {
        [OperationContract]
        NBusquedacampana wsDataBusqueda(string identificacion, string nombres, string correo, string fuente, string idcanal, string ip);

    }

    // Utilice un contrato de datos, como se ilustra en el ejemplo siguiente, para agregar tipos compuestos a las operaciones de servicio.
    [DataContract]

    public class NBusquedacampana
    {
        String _Rpta;
        [DataMember]
        public String Rpta
        {
            get { return _Rpta; }
            set { _Rpta = value; }
        }
    }

This is my code in .svc

public NBusquedacampana wsDataBusqueda(string identificacion, string nombres, string correo, string fuente, string idcanal, string ip)
        {
            String _Rpta;

            if(identificacion =="")
            {
                _Rpta = "Ingrese el Dni";
                return new NBusquedacampana() { Rpta = _Rpta };
            }

            if (identificacion ==null)
            {
                _Rpta = "Ingrese el Dni";
                return new NBusquedacampana() { Rpta = _Rpta };
            }

            if (nombres == "")
            {
                _Rpta = "Ingrese el nombre";
                return new NBusquedacampana() { Rpta = _Rpta };
            }
            if (nombres ==null)
            {
                _Rpta = "Ingrese el Dni";
                return new NBusquedacampana() { Rpta = _Rpta };
            }

            if (correo == "")
            {
                _Rpta = "Ingrese el Correo";
                return new NBusquedacampana() { Rpta = _Rpta };
            }
            if (correo ==null)
            {
                _Rpta = "Ingrese el Dni";
                return new NBusquedacampana() { Rpta = _Rpta };
            }
            if (fuente == "")
            {
                _Rpta = "Ingrese la fuente";
                return new NBusquedacampana() { Rpta = _Rpta };
            }
            if (fuente ==null)
            {
                _Rpta = "Ingrese el Dni";
                return new NBusquedacampana() { Rpta = _Rpta };
            }
            if (idcanal == "")
            {
                _Rpta = "Ingrese el canal";
                return new NBusquedacampana() { Rpta = _Rpta };
            }
            if (idcanal ==null)
            {
                _Rpta = "Ingrese el Dni";
                return new NBusquedacampana() { Rpta = _Rpta };
            }
            else
            {
                _Rpta = nECampanas.wsDataBusqueda(identificacion, nombres, correo, fuente, idcanal, ip);
                return new NBusquedacampana() { Rpta = _Rpta };


            }


        }
    
asked by PieroDev 27.01.2018 в 19:03
source

0 answers