v1tal1ty Posted July 12, 2012 at 01:27 PM Report Share #468479 Posted July 12, 2012 at 01:27 PM Boa tarde caros colegas. Estou com uns problemas em configurar o serviço wcf. Nao consigo aceder aos dados porque o ficheiro web config nao deve estar bem configurado. Se alguem me conseguir ajudar, agradeco. E deste ja peço desculpa pelos meus conhecimentos limitados... Aqui tem o meu codigo Service.cs using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; namespace Origin { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together. [serviceContract] public interface IService1 { [OperationContract] string GetData(int value); [OperationContract] CompositeType GetDataUsingDataContract(CompositeType composite); [OperationContract] int Check(string Username, string Password); // TODO: Add your service operations here } // Use a data contract as illustrated in the sample below to add composite types to service operations. [DataContract] public class CompositeType { bool boolValue = true; string stringValue = "Hello "; [DataMember] public bool BoolValue { get { return boolValue; } set { boolValue = value; } } [DataMember] public string StringValue { get { return stringValue; } set { stringValue = value; } } } } Service.svc.cs using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; using System.Data.SqlClient; namespace Origin { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together. public class Service1 : IService1 { public string GetData(int value) { return string.Format("You entered: {0}", value); } public CompositeType GetDataUsingDataContract(CompositeType composite) { if (composite == null) { throw new ArgumentNullException("composite"); } if (composite.BoolValue) { composite.StringValue += "Suffix"; } return composite; } public int Check(string Username, string Password) { SqlConnection conn = new SqlConnection(@"Data Source=WINDOWSPHONE-PC\SQLEXPRESS;Initial Catalog=ISTEC;Integrated Security=True"); conn.Open(); string nome = ""; string pass = ""; SqlDataReader myReader = null; SqlCommand myCommand = new SqlCommand("select * from Alunos where Aluno = '" + Username + "'", conn); myReader = myCommand.ExecuteReader(); if (myReader.HasRows) { nome = myReader.GetSqlValue(1).ToString(); pass = myReader.GetValue(2).ToString(); } conn.Close(); string aux = pass; //pass = Encrypt(aux); if (nome == Username && pass == Password) { return 1; } else return 0; } } } Web.Config <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="true"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration> Link to comment Share on other sites More sharing options...
v1tal1ty Posted July 13, 2012 at 10:05 AM Author Report Share #468548 Posted July 13, 2012 at 10:05 AM Nao ha ninguem que me ajuda? Link to comment Share on other sites More sharing options...
bruno1234 Posted July 13, 2012 at 06:16 PM Report Share #468624 Posted July 13, 2012 at 06:16 PM Obténs algum erro? Matraquilhos para Android. Gratuito na Play Store. https://play.google.com/store/apps/details?id=pt.bca.matraquilhos Link to comment Share on other sites More sharing options...
v1tal1ty Posted July 16, 2012 at 09:22 AM Author Report Share #468807 Posted July 16, 2012 at 09:22 AM Da me "Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service." mais detalhes do erro. "The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs. Server stack trace: at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) " Para alem disso. tenho limite de acesso aos dados de Myreader public int Check(string Username, string Password) { SqlConnection conn = new SqlConnection(@"Data Source=WINDOWSPHONE-PC\SQLEXPRESS;Initial Catalog=ISTEC;Integrated Security=True"); conn.Open(); string nome = ""; string pass = ""; SqlDataReader myReader = null; SqlCommand myCommand = new SqlCommand("select * from Alunos where Aluno = '" + Username + "'", conn); myReader = myCommand.ExecuteReader(); if (myReader.HasRows) { nome = myReader.GetSqlValue(1).ToString(); pass = myReader.GetValue(2).ToString(); // No myreader me aparece que existem dados, mas nao os consigo aceder de nenhuma forma } conn.Close(); string aux = pass; //pass = Encrypt(aux); if (nome == Username && pass == Password) { return 1; } else return 0; } Link to comment Share on other sites More sharing options...
bruno1234 Posted July 16, 2012 at 06:23 PM Report Share #468909 Posted July 16, 2012 at 06:23 PM Pelo erro algo está mal com o teu proxy ou com a configuração. Experimenta gerar novamente o proxy, Matraquilhos para Android. Gratuito na Play Store. https://play.google.com/store/apps/details?id=pt.bca.matraquilhos Link to comment Share on other sites More sharing options...
v1tal1ty Posted July 19, 2012 at 08:49 AM Author Report Share #469230 Posted July 19, 2012 at 08:49 AM Boas de novo. Eu sei que esta mal configurado o server. Mas é por esta mesma razao que estou aqui. Há 1 semana estou a tentar configurar, mas nao consigo. Porque tenho conhecimentos bastantes limitados. Os sites que estive a consultar não era nada explicito. Se alguem me pudesse dar uma maozinha no ficheiro web config era ja uma grande ajuda. Link to comment Share on other sites More sharing options...
bruno1234 Posted July 19, 2012 at 07:35 PM Report Share #469277 Posted July 19, 2012 at 07:35 PM O que tens no config do cliente? Matraquilhos para Android. Gratuito na Play Store. https://play.google.com/store/apps/details?id=pt.bca.matraquilhos Link to comment Share on other sites More sharing options...
v1tal1ty Posted July 20, 2012 at 08:46 AM Author Report Share #469330 Posted July 20, 2012 at 08:46 AM Eu utilizo WCF test client. E config dele é: <?xml version="1.0" encoding="utf-8"?> <configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://localhost:2989/Service1.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" contract="IService1" name="BasicHttpBinding_IService1" /> </client> </system.serviceModel> </configuration> Eu tenho o cliente, mas é wp7, e ainda nao ligei ao serviço. Link to comment Share on other sites More sharing options...
bruno1234 Posted July 20, 2012 at 06:11 PM Report Share #469418 Posted July 20, 2012 at 06:11 PM Assim de repente não estou a ver. Experimenta colocar a informação detalhada de excepções no servidor. Nesta linha do web.config do serviço: <serviceDebug includeExceptionDetailInFaults="false"/> coloca o valor a true. Pode ser que assim a excepção dê mais detalhes do que se passa. Matraquilhos para Android. Gratuito na Play Store. https://play.google.com/store/apps/details?id=pt.bca.matraquilhos Link to comment Share on other sites More sharing options...
v1tal1ty Posted July 26, 2012 at 09:47 AM Author Report Share #470397 Posted July 26, 2012 at 09:47 AM Da me "Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service." mais detalhes do erro. "The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs. Server stack trace: at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) " Aqui tinhas Link to comment Share on other sites More sharing options...
RGanhoto Posted January 3, 2015 at 04:23 PM Report Share #574139 Posted January 3, 2015 at 04:23 PM Boa Tarde. há aqui umas questões que gostaria de saber: 1. Consegues aceder ao WCF a partir do browser do pc? 2. Consegues aceder ao WCF a partir do browser de outro pc que não o servidor? 3. Consegues aceder ao WCF a partir do telemóvel? 4. O Config do teu cliente, estranhamente tem como endpoint o "LocalHost" deveria ter ou o IP ou endereço do Servidor que faz host ao WCF. Se estás a fazer debug no Visual studio ao WCF. não é possível aceder extenamente ao serviço usado o IIS express. Tens de abrir o Visual studio como administrador, nas propriedades do projeto do WCF no separador WEB, definir para usar o Local IIS. Com o novo endereço no endpoint já irás conseguir aceder ao serviço com o telemóvel / outros pc's. Cumprimentos. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now