Rodo in the browser my WebService and gives me a strange message

1

When giving a View In Browser in my WebService, brought me this message. It does not look like a message that the WebService is all ok. What message is this?

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.

I'm crawling with WCF at a slow pace. I was adding a reference to my windows forms project to consume the web service method and see what happened. I understood that REST does not adiuciona reference, right?

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.

In my solution I have some projects. A class library project where I have a POCO class and an 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; }
    ......

and my interface

namespace V99SuporteTecnicoContracts
{
    [ServiceContract]
    public interface ISuporteTecnicoContract
    {
        [OperationContract]
        //[WebGet(UriTemplate = "/{_cnpj}")]
        [WebInvoke(Method="POST", ResponseFormat=WebMessageFormat.Xml)]
        TPDV getCnpjParceiro(string _cnpj);
    }
}

Well, besides I have the svc itself. Below his source

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;
        }
    }
}

and service web.config (.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=&quot;data source=54.187.114.104;initial catalog=V99;persist security info=True;user id=V99App;password=V99@1032ab;MultipleActiveResultSets=True;App=EntityFramework&quot;" 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=&quot;data source=54.187.114.104;initial catalog=V99_WEB;persist security info=True;user id=V99App;password=V99@1032ab;MultipleActiveResultSets=True;App=EntityFramework&quot;" 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=&quot;data source=54.187.114.104;initial catalog=V99_OLAP;persist security info=True;user id=V99App;password=V99@1032ab;MultipleActiveResultSets=True;App=EntityFramework&quot;" 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>

When I try to use the WCF Client, it does not give me the field for entering my parameter cnpj. I believe there is "ox on the line" of web.config.

My new service.model tag in 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>

I made changes to my App.config and looked like this:

<?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>

The message has now changed. It's a runtime message and the message is this:

The remote server returned an unexpected response:(400) bad request.
    
asked by anonymous 15.05.2014 / 14:34

2 answers

3

This is the default message displayed when trying to access a WebService in the browser without having the metadata enabled.

A WebService, by default, is not meant to be viewed directly in a browser, such as an HTML page, or a photo.

When I need to test a WebService (be it ASMX, or any other type), I use a new instance of Visual Studio with a new dummy project in C #, as shown below:

IfitisaWCFservice,andyouhavetheWCFTestClientapplicationinstalled,youcanalsouseittotestaservice:

*Onmycomputer,itstayshere:C:\ProgramFiles(x86)\MicrosoftVisualStudio12.0\Common7\IDE\WcfTestClient.exe

    
15.05.2014 / 14:48
1

Friend, I realized that you did not even call the methods of your webService either (hello ... or dowork ..). Do not forget the new one in your project.

Well, I also noticed that you are not referring to the service in the right way. There is a certain difference between Service and WebService. The correct way for you to perform the reference would be this:

To add a Web Part to your project: In Solution Explorer, right-click the name of the project that you want to add the service to. Then click Add Service Reference. The Add Service Reference window appears, click the Advanced button. The Service Reference Settings window will appear, clicking on it: Add Web Reference. Then just put the url and etc ...

There is a difference in both ways of adding a reference in Visual Studio. So it requires this certain knowledge. Then you do as I said to give the new in reference and use their methods.

    
16.05.2014 / 21:39