Server Erro application WCF
09/02/2015
0
[img]http://arquivo.devmedia.com.br/forum/imagem/337411-20150209-221034.jpg[/img]
Fernanda Acacia
Posts
10/02/2015
Soeuseijothaz
[img]http://arquivo.devmedia.com.br/forum/imagem/337411-20150209-221034.jpg[/img]
Para facilitar a ajuda poste o código do WebService, config.xml e da chamada para consumi-lo.
10/02/2015
Fernanda Acacia
config.xml
<?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.5" /> <httpRuntime targetFramework="4.5" /> </system.web> <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"> <serviceActivations> <add factory="System.ServiceModel.Activation.ServiceHostFactory" relativeAddress="~/ServicoHost/OlaMundoService.svc" service="Servico.OlaMundoService"/> </serviceActivations> </serviceHostingEnvironment> <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>
OlaMundoService.cs
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace Servico { public class OlaMundoService : IOlaMundoService { public string OlaMundo() { return "Olá Mundo = WCF"; } } }
IOlaMundoService.cs
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace Servico { [ServiceContract] public interface IOlaMundoService { [OperationContract] string OlaMundo(); } }
OlaMundoService.svc
11/02/2015
Soeuseijothaz
Olha eu uso o web.conf da página que vai consumir o serviço assim,:
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IService1" /> </basicHttpBinding> </bindings> <client> <endpoint address="http://localhost:58779/Service1.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" /> </client> </system.serviceModel> </configuration>
E o App.config do serviço assim:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.web> <compilation debug="true" /> </system.web> <!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. --> <system.serviceModel> <services> <service name="ServicoWCF.CalcService" behaviorConfiguration="ServicoWCF.Service1Behavior"> <host> <baseAddresses> <add baseAddress = "http://localhost:8731/Design_Time_Addresses/ServicoWCF/Service1/" /> </baseAddresses> </host> <!-- Service Endpoints --> <!-- Unless fully qualified, address is relative to base address supplied above --> <endpoint address ="" binding="wsHttpBinding" contract="ServicoWCF.ICalcService"> <!-- Upon deployment, the following identity element should be removed or replaced to reflect the identity under which the deployed service runs. If removed, WCF will infer an appropriate identity automatically. --> <identity> <dns value="localhost"/> </identity> </endpoint> <!-- Metadata Endpoints --> <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> <!-- This endpoint does not use a secure binding and should be secured or removed before deployment --> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="ServicoWCF.Service1Behavior"> <!-- 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> </system.serviceModel> </configuration>
Não se esqueça de adicionar em "References" o serviço via "Add Service Reference".
E claro, se você não publicou o serviço no seu IIS, deve rodá-lo em paralelo com a aplicação que vai consumi-lo.
Segue um link bem completo:
Criando e consumindo serviços com WCF
11/02/2015
Fernanda Acacia
11/02/2015
Soeuseijothaz
Uma das vantagens das linguagens atuais é usar vários Namespaces e poder referencia-los a vontade.
Você pode criar os projetos da forma que você quiser, você define a arquitetura, é só referencia-los onde for usar.
Clique aqui para fazer login e interagir na Comunidade :)