Usuário com melhor resposta
Username/Password para o WCF com Silverlight sem HTTPS tem como?

Pergunta
-
Boa tarde,
Gostaria de saber se é possível usar username/password em um serviço wcf sem que seja necessário disponibilizar por https? se sim como fazer, pois fiz o processo para disponibilizar via https mas não tenho um certificado gerei um pelo IIS7 mas o navegador fica com a mensagem de certificado invalido com isso meu client em Silverlight não consegue acesso aos métodos do wcf.
Atenciosamente,
Obrigado.
Respostas
-
Boas Manoel,
Já que você não quer utilizar HTTPS, então você poderia anexar o login/senha nos headers da requisição, e quando ela chegar do lado do serviço, você pode interceptar a requisição via behaviors/inspectors, e validar o usuário antes de executar a operação.
http://www.israelaece.com- Marcado como Resposta Manoel Bruno P. Lima terça-feira, 5 de julho de 2011 12:05
Todas as Respostas
-
Manoel,
Vc pode definir isso na sua configuração de Binding do serviço de autenticação
faça as alterações no web.config para ficar parecido com isso
<system.web.extensions> <scripting> <webServices> <authenticationService enabled="true" requireSSL = "false"/> </webServices> </scripting> </system.web.extensions> <bindings> <customBinding> <binding name="unsecureBinding"> <binaryMessageEncoding /> <httpTransport/> </binding> </customBinding> </bindings> <service name="AuthenticationService"> <endpoint address="" binding="customBinding" bindingConfiguration="unsecureBinding" contract="AuthenticationService" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service>
-
Boa Tarde, Rui Santos.
Fiz as alterações no web.config do projeto que tem o serviço WCF mas quando rodo a aplicação silverlight não ocorre nenhum erro mesmo não passando username/password para o servciço wcf.
Web.Config do projeto WCF
<configuration> <connectionStrings> <clear /> <add name="SuporteWEBConnectionString" connectionString="Data Source=WebSERVER\SQLEXPRESS;Initial Catalog=SuporteWEB;User ID=sa; Password=******" providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <compilation debug="true" targetFramework="4.0" /> <authentication mode="Forms"> <forms loginUrl="Login.aspx" path="/"/> </authentication> <authorization> <allow users="*"/> </authorization> <membership defaultProvider="CustomMembershipProvider"> <providers> <clear/> <add name="CustomMembershipProvider" type="AppSuporte.Web.Classes.CustomMembershipProvider" connectionString="SuporteWEBConnectionString"/> </providers> </membership> <roleManager defaultProvider="CustomRoleProvider" enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All"> <providers> <clear/> <add name="CustomRoleProvider" type="AppSuporte.Web.Classes.CustomRoleProvider" connectionString="SuporteWEBConnectionString" applicationName="AppSuporte"/> </providers> </roleManager> <customErrors mode="Off"/> </system.web> <system.web.extensions> <scripting> <webServices> <authenticationService enabled="true" requireSSL = "false"/> </webServices> </scripting> </system.web.extensions> <system.serviceModel> <services> <service name="AuthenticationService"> <endpoint address="" name="srv" binding="customBinding" contract="IwebService" bindingConfiguration="unsecureBinding"/> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> <serviceCredentials> <userNameAuthentication userNamePasswordValidationMode="MembershipProvider" membershipProviderName="CustomMembershipProvider"/> </serviceCredentials> </behavior> </serviceBehaviors> </behaviors> <bindings> <customBinding> <binding name="unsecureBinding"> <binaryMessageEncoding /> <httpTransport/> </binding> </customBinding> </bindings> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration>
Na aplicação silverlight cliente tenho o arquivo. ServiceReferences.ClientConfig<configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IwebService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <security mode="None" /> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://suporte.mercosistem.intranet/WebService/webService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IwebService" contract="ServiceWeb.IwebService" name="BasicHttpBinding_IwebService" /> </client> </system.serviceModel> </configuration>
e uso o serviço da seguinte forma: (OBS: não passei usuário e senha e mesmo assim funcionou!.)private void btnPesquisa_Click(object sender, RoutedEventArgs e) { busyIndicator1.IsBusy = true; IwebServiceClient _WebClient = new IwebServiceClient(); _WebClient.OpenAsync(); _WebClient.CarregaUsuarioPorFiltroAsync(txtPesquisa.Text); _WebClient.CarregaUsuarioPorFiltroCompleted += new EventHandler<CarregaUsuarioPorFiltroCompletedEventArgs>(CarregaUsuarioPorFiltroCompleted); _WebClient.CloseAsync(); } private void CarregaUsuarioPorFiltroCompleted(object sender, CarregaUsuarioPorFiltroCompletedEventArgs e) { PagedCollectionView PagedResult = new PagedCollectionView(e.Result); GridUsuario.ItemsSource = PagedResult; busyIndicator1.IsBusy = false; }
-
-
-
Ola Manoel,
da uma olhada neste artigo...
-
Boa Tarde, Rui.
Tentei fazer o exemplo em um novo projeto e o mesmo me retorna do servidor a seguinte mensagem, com isso não consigo adicionar a referencia no
silverlight pois não aparece o metadata.
Metadata publishing for this service is currently disabled.
If you have access to the service, you can enable metadata publishing by completing the following steps to modify your web or application configuration file:
Mas segue a configuração do Web.Config esta certo igual ao exemplo:
<?xml version="1.0"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <services> <service behaviorConfiguration="ServiceBehavior" name="HelloService"> <host> <baseAddresses> <add baseAddress="http://localhost"/> </baseAddresses> </host> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="test" contract="IHelloSayer"> <identity> <dns value="localhost"/> </identity> </endpoint> <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/> </service> </services> <bindings> <basicHttpBinding> <binding name="test"> <security mode="TransportWithMessageCredential"> <message clientCredentialType="UserName"/> </security> </binding> </basicHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="ServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> <serviceCredentials> <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyValidator, SilverlightApplication2.Web"/> </serviceCredentials> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> </configuration>
Atenciosamente,
-
Boas Manoel,
Já que você não quer utilizar HTTPS, então você poderia anexar o login/senha nos headers da requisição, e quando ela chegar do lado do serviço, você pode interceptar a requisição via behaviors/inspectors, e validar o usuário antes de executar a operação.
http://www.israelaece.com- Marcado como Resposta Manoel Bruno P. Lima terça-feira, 5 de julho de 2011 12:05
-