Tengo un Servicio al cual quiero ponerle una pequeña autentificación personalizada, para permitir el acceso al mismo.
En principio, creo que lo he configurado todo bien, pero tengo dos problemas.
1-. Cuando ejecuto el Servicio, en el navegador no puedo acceder al mismo, y me da el siguiente mensaje de error desde el navegador:
Código:
Bien, para solucionar este problema, fui al IIS, y en el Directorio Virtual de la aplicación, habilite la autentificación Basica. De esta forma, al intentar acceder al servicio através del navegador, ya puedo ver el metadata, e incluso generar la librería cliente.La configuración de seguridad de este servicio requiere la autenticación 'Basic', pero no está habilitada para la aplicación IIS que hospeda este servicio
2-. El siguiente error es el que no soy capaz de solucionar, y es que desde el cliente, intento ejecutar un método del servicio y me sale el siguiente mensaje de error en la excepción:
Código:
La solicitud HTTP no está autorizada con el esquema de autenticación de cliente 'Basic'. El encabezado de autenticación recibido del servidor era 'Basic realm="pchevia"'
Bien... la verdad es que he revisado a full mi configuración, tanto cliente, como servidor, pero... no tengo ni puta idea de que puede pasar... pero en fin.. espero puedan ayudarme.
CONFIGURACION SERVIDOR
Código:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttpBindingDefault">
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="None">
</transport>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="behaviorDefault">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="ValidationShop, App_Code"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<services>
<service name="Service" behaviorConfiguration="behaviorDefault">
<endpoint binding="wsHttpBinding" bindingConfiguration="wsHttpBindingDefault" contract="IService" />
<endpoint name="mex"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
CONFIGURACION CLIENTE
Código:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="None" realm="" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://pchevia/wcfShop/Service.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService" contract="ShopService.IService"
name="WSHttpBinding_IService" />
</client>
</system.serviceModel>
</configuration>
LLAMADA DESDE EL CLIENTE
Código:
public string MyProperty { get; set; }
private void button1_Click(object sender, EventArgs e)
{
try
{
using (ShopService.ServiceClient objClient = new ShopService.ServiceClient())
{
objClient.ClientCredentials.UserName.UserName = "MIUSUARIO";
objClient.ClientCredentials.UserName.Password = "MICLAVE";
this.MyProperty = objClient.GetData(2);
}
MessageBox.Show(MyProperty);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
En fin... cualquier ayuda, será bien agradecida jeje, saludos.


