Inquiridor
WCF funciona em desenvolvimento mas não funciona em produção ( erro de segurança )

Pergunta
-
Senhores,
Estou com um problema quando consumo meu WCF externamente à minha rede, quando acesso pela rede interna funciona normalmente, o erro que me retorna quando tento dar um Open() em meu WCF é o seguinte: O chamador não foi autenticado pelo serviço.
O serviço está com a seguinte config:
<system.serviceModel> <bindings> <wsHttpBinding> <binding name="NewBinding0" closeTimeout="00:01:50" openTimeout="00:01:05" receiveTimeout="00:10:05" sendTimeout="00:01:05" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="100" maxStringContentLength="100" maxArrayLength="100" maxBytesPerRead="100" maxNameTableCharCount="100" /> </binding> </wsHttpBinding> </bindings> <services> <service behaviorConfiguration="ConstruWeb.Web.Services.ServOrcamentoBehavior" name="ConstruWeb.Web.Services.ServOrcamento" > <endpoint address="" binding="wsHttpBinding" contract="ConstruWeb.Web.Services.IServOrcamento" bindingConfiguration="NewBinding0"> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ConstruWeb.Web.Services.ServOrcamentoBehavior"> <serviceMetadata httpGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
E o Cliente está com a seguinte config:
<system.serviceModel> <bindings> <wsHttpBinding> <binding name="wsHttpBinding_IServOrcamento" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="false" allowCookies="false"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> </binding> </wsHttpBinding> </bindings> <client> <endpoint address="http://189.85.26.130/teste/services/servorcamento.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IServOrcamento" contract="ServOrcamento.IServOrcamento" name="wsHttpBinding_IServOrcamento" /> </client> </system.serviceModel>
Todas as Respostas
-
Boas Rodrigo,
Por padrão, o WSHttpBinding está configurado como autenticação Windows.
Acho que não teu caso não precisará disso, então você pode desligá-lo através da configuração do binding dos dois lados (cliente e serviço):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="NewBinding0">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
http://www.israelaece.com -
Olá Israel,
Primeiramente obrigado pelo apoio.
Coloquei a tag nos configs ( Servidor e Cliente ) mas agora ocorreu um novo erro ao tentar acessar um método do contrato, agora consegui fazer o Open() no cliente mas quando acessado qualquer método do contrato ocorre o seguinte erro:
O canal de solicitação atingiu o tempo limite ao aguardar uma resposta depois de 00:00:59.6723994. Aumente o valor de tempo limite transmitido à chamada para Request ou aumente o valor de SendTimeout na Ligação. O tempo determinado para essa operação pode ter sido uma parte de um tempo limite mais longo.
-
-
Boas Rodrigo,
Poste aqui os arquivos de configuração do cliente e do serviço.
http://www.israelaece.com -
Israel,
O Erro acima eu descobri... era o caminho do serviço que estava incorreto. Configurei corretamente o caminho e ocorreu um novo erro :
The message could not be processed. This is most likely because the action 'http://tempuri.org/IServOrcamento/TestConnection' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.
O config do Serviço está da seguinte maneira:
<system.serviceModel> <bindings> <wsHttpBinding> <binding name="NewBinding0" closeTimeout="00:01:50" openTimeout="00:01:05" receiveTimeout="00:10:05" sendTimeout="00:10:05" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="100" maxStringContentLength="100" maxArrayLength="100" maxBytesPerRead="100" maxNameTableCharCount="100" /> <security mode="None" /> </binding> </wsHttpBinding> </bindings> <services> <service behaviorConfiguration="ConstruWeb.Web.Services.ServOrcamentoBehavior" name="ConstruWeb.Web.Services.ServOrcamento" > <endpoint address="" binding="wsHttpBinding" contract="ConstruWeb.Web.Services.IServOrcamento" bindingConfiguration="NewBinding0"> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ConstruWeb.Web.Services.ServOrcamentoBehavior"> <serviceMetadata httpGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
E o config do Cliente está da seguinte maneira:
<system.serviceModel> <bindings> <wsHttpBinding> <binding name="wsHttpBinding_IServOrcamento" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="false" allowCookies="false" > <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="None" /> </binding> </wsHttpBinding> </bindings> <client> <endpoint address="http://189.85.26.110/Construweb_Demo/services/servorcamento.svc" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IServOrcamento" contract="ServOrcamento.IServOrcamento" name="wsHttpBinding_IServOrcamento" /> </client> </system.serviceModel>
-
Boas Rodrigo,
Faltou você ligar a configuração binding no serviço:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="NewBinding0" closeTimeout="00:01:50" openTimeout="00:01:05"
receiveTimeout="00:10:05" sendTimeout="00:10:05" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="100" maxStringContentLength="100" maxArrayLength="100"
maxBytesPerRead="100" maxNameTableCharCount="100" />
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ConstruWeb.Web.Services.ServOrcamentoBehavior"
name="ConstruWeb.Web.Services.ServOrcamento" >
<endpoint address="" binding="wsHttpBinding" contract="ConstruWeb.Web.Services.IServOrcamento" bindingConfiguration="NewBinding0">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" bindingConfiguration="NewBinding0" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ConstruWeb.Web.Services.ServOrcamentoBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
http://www.israelaece.com -
Israel,
Continuamos com o mesmo erro:
The message could not be processed. This is most likely because the action 'http://tempuri.org/IServOrcamento/TestConnection' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.
-
-
Boas Rodrigo,
Eu pedi para você colocar a configuração do binding no endpoints de metadados, mas não era isso que queria. O correto é você ter vinculado somente no endpoint de cima, qual já está correto.
Você está utilizando o WCF 4.0? Se sim, de certeza que o nome do serviço (ConstruWeb.Web.Services.ServOrcamento) no Web.config está apontando para a classe corretamente? Já tentou refazer a referência no cliente?!
http://www.israelaece.com -
Israel,
Voltei como estava a configuração do metadados.
O WCF está na versão 3.5 e está correto se não não funcionaria em ambiente local ( cliente e servidor na mesma rede ) eu acho.
Referência no cliente que vc citou é o service reference???
-
Boas Rodrigo,
Isso, atualizar a referência do lado do cliente para refazer a configuração, que agora está com a segurança desligada.
http://www.israelaece.com -
-
Boas Rodrigo,
Agora me mostra como está o arquivo de configuração que foi criado no cliente.
http://www.israelaece.com -
Israel,
Segue o arquivo cliente:
<system.serviceModel> <bindings> <wsHttpBinding> <binding name="WSHttpBinding_IServOrcamento" 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="None"/> </binding> </wsHttpBinding> </bindings> <client> <endpoint address="http://189.85.26.30/Construweb_Demo/services/ServOrcamento.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IServOrcamento" contract="ServOrcamento.IServOrcamento" name="WSHttpBinding_IServOrcamento"> <identity> <dns value="localhost" /> </identity> </endpoint> </client> </system.serviceModel>
-
Boas Rodrigo,
Remova isso:
<identity>
<dns value="localhost" />
</identity>
- Sugerido como Resposta Luiz Bueno quinta-feira, 18 de abril de 2013 17:10