Ao dar um View In Browser no meu WebService, me trouxe essa mensagem. Não parece com uma mensagem de que o WebService está tudo ok. Que mensagem é essa?
Service
This is a Windows© Communication Foundation service.
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:
1. Create the following service behavior configuration, or add the <serviceMetadata> element to an existing service behavior configuration:
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
2. Add the behavior configuration to the service:
<service name="MyNamespace.MyServiceType" behaviorConfiguration="MyServiceTypeBehaviors" >
Note: the service name must match the configuration name for the service implementation.
3. Add the following endpoint to your service configuration:
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
Note: your service must have an http base address to add this endpoint.
The following is an example service configuration file with metadata publishing enabled:
<configuration>
<system.serviceModel>
<services>
<!-- Note: the service name must match the configuration name for the service implementation. -->
<service name="MyNamespace.MyServiceType" behaviorConfiguration="MyServiceTypeBehaviors" >
<!-- Add the following endpoint. -->
<!-- Note: your service must have an http base address to add this endpoint. -->
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<!-- Add the following element to your service behavior configuration. -->
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
For more information on publishing metadata please see the following documentation: http://go.microsoft.com/fwlink/?LinkId=65455.
Estou engatinhando com WCF a passos lentos. Fui adicionar uma referência ao meu projeto windows forms para consumir o método do web service e veja o que ocorreu. Entendi que REST não se adiuciona referência, certo?
There was an error downloading 'http://localhost:4600/SuporteTecnicoService.svc/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 404: Not Found.
Metadata contains a reference that cannot be resolved: 'http://localhost:4600/SuporteTecnicoService.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:4600/SuporteTecnicoService.svc. The client and service bindings may be mismatched.
The remote server returned an error: (415) Unsupported Media Type.
If the service is defined in the current solution, try building the solution and adding the service reference again.
Na minha solution tenho alguns projetos. Um projeto class library onde tenho uma classe POCO e uma Interface.
namespace V99SuporteTecnicoContracts
{
[Table(Name="T_PDV")]
[DataContract(Namespace="")]
public class TPDV
{
[Column]
[DataMember]
public int IDPdv { get; set; }
[Column]
[DataMember]
public string CNPJ { get; set; }
[Column]
[DataMember]
public string RazaoSocial { get; set; }
......
e a minha interface
namespace V99SuporteTecnicoContracts
{
[ServiceContract]
public interface ISuporteTecnicoContract
{
[OperationContract]
//[WebGet(UriTemplate = "/{_cnpj}")]
[WebInvoke(Method="POST", ResponseFormat=WebMessageFormat.Xml)]
TPDV getCnpjParceiro(string _cnpj);
}
}
Bem, além disso tenho o svc propriamente dito. Abaixo o fonte dele
namespace SuporteTecnicoService
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class SuporteTecnico : ISuporteTecnicoContract
{
public TPDV getCnpjParceiro(string _cnpj)
{
V99_WEB_QAEntities db = new V99_WEB_QAEntities();
TPDV pdv = new TPDV();
List<string> lista = new List<string>();
//DataContext contexto = new DataContext();
var resultado = (from _lista in db.T_PDV
where _lista.CNPJ == _cnpj
select new { _lista.CNPJ, _lista.RazaoSocial, _lista.Endereco}).ToList();
foreach (var lis in resultado)
{
pdv.CNPJ = lis.CNPJ;
pdv.RazaoSocial = lis.RazaoSocial;
pdv.Endereco = lis.Endereco;
}
return pdv;
}
}
}
e o web.config do serviço(.SVC)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="V99_QAEntities" connectionString="metadata=res://*/Models.V99.csdl|res://*/Models.V99.ssdl|res://*/Models.V99.msl;provider=System.Data.SqlClient;provider connection string="data source=54.187.114.104;initial catalog=V99;persist security info=True;user id=V99App;password=V99@1032ab;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="V99_WEB_QAEntities" connectionString="metadata=res://*/Models.V99_Web.csdl|res://*/Models.V99_Web.ssdl|res://*/Models.V99_Web.msl;provider=System.Data.SqlClient;provider connection string="data source=54.187.114.104;initial catalog=V99_WEB;persist security info=True;user id=V99App;password=V99@1032ab;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="V99_OLAP_QAEntities" connectionString="metadata=res://*/Models.V99_Olap.csdl|res://*/Models.V99_Olap.ssdl|res://*/Models.V99_Olap.msl;provider=System.Data.SqlClient;provider connection string="data source=54.187.114.104;initial catalog=V99_OLAP;persist security info=True;user id=V99App;password=V99@1032ab;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<services>
<service name="SuporteTecnico">
<endpoint address="" binding="webHttpBinding" contract="V99SuporteTecnicoContracts.ISuporteTecnicoContract" behaviorConfiguration="WebBehavior" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!--To avoid disclosing metadata information, set the values below to false before deployment-->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
Quando eu tento usar o WCF Client, ele não me disponibiliza o campo referente a entrar com meu parâmetro cnpj. Creio que tem "boi na linha" do web.config.
Minha nova tag service.model no web.config.
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!--To avoid disclosing metadata information, set the values below to false before deployment-->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Fiz alterações em meu App.config e ficou assim:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="TesteWebService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISuporteTecnicoContract" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:4600/SuporteTecnicoService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISuporteTecnicoContract"
contract="SuporteTecnicoContractClient.ISuporteTecnicoContract"
name="BasicHttpBinding_ISuporteTecnicoContract" />
<endpoint address="http://localhost:4600/SuporteTecnicoService.svc"
binding="webHttpBinding"
contract="V99SuporteTecnicoContracts.ISuporteTecnicoContract"
behaviorConfiguration="WebBehavior"
name="BasicHttpBinding_ISuporteTecnicoContract" />
</client>
</system.serviceModel>
<applicationSettings>
<TesteWebService.Properties.Settings>
<setting name="TesteWebService_ServiceSuporteTecnico_SuporteTecnico"
serializeAs="String">
<value>http://localhost:4600/SuporteTecnicoService.svc</value>
</setting>
</TesteWebService.Properties.Settings>
</applicationSettings>
</configuration>
A mensagem agora mudou. É uma mensagem em runtime e a mensagem é essa:
The remote server returned an unexpected response:(400) bad request.