I rotate in my browser Webservice and gives me a strange message

Asked

Viewed 529 times

1

While giving a View In Browser on my Webservice, brought me this message. It doesn’t look like a message that Webservice is all ok. What is this message?

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 slow paces. I went to add a reference to my windows Forms project to consume the web service method and see what happened. I understood that REST does not add 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, I also 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 the 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 WCF Client, it does not provide me with the field for entering my cnpj parameter. I believe there is "ox on the line" of the web.config.

My new service.model tag on the 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 in my App.config and it was 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 that’s the message:

The remote server returned an unexpected response:(400) bad request.
  • You can send a screenshot of your WCF Client? This is very mysterious... Here it worked so fast... :(

  • I will send all my project. It has how to attach file here on the forum?

  • Unfortunately, there is no such possibility.

2 answers

3

This is the default message shown when trying to access a Webservice in the browser, without having the metadata enabled.

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

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

Etapa 1

Etapa 2

Etapa 3

If it’s a WCF service, and you have the app WCF Test Client installed, you can also use it to test a service:

*On my computer, he stays here: C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\WcfTestClient.exe

Etapa 4

Etapa 5

Etapa 6

  • You can add normally. But this scheme of how to test is just one example. If you have installed it, you can also test the WebService through the Microsoft WCF Test Client.

  • I edited the answer with this other example...

  • It provides that field(s) (s) automatically when a method has parameters.

  • To better determine, I would need to see the code of svc and of cs.

  • Hi @pnet! You should edit the question, not the answer ;)

  • Hi again, @pnet! I tested your code, and I did it exactly the same. It worked perfect, but three things you should note: 1. Check all namespace, and see if they’re hitting. 2. Check out the Markup of the archive SuporteTecnico.svc and see if he’s okay. 3. I removed the entrance <services><service name="SuporteTecnico">...</services> of Web.config.

  • When you say it works, you mean you can pass the parking meter to the WS? Because the screen that says that the WS started, for me also is shown. What I can’t do is pass the cnpj parameter, or the WCF Clienttest, or the application I developed for it. Error continues:The type initializer for 'System.ServiceModel.Diagnostics.Traceutility' threw an Exception.

  • Yes, including passing parameters! Tried to delete that excerpt I told you, from Web.config? Also try to remove the attribute [DataContract(Namespace="")] of your class TPDV, because I didn’t add it during my tests.

  • Yes, delete yes. Delete all tags from <service><services>, all within these tags. I will edit my question and put my new web.config. In case you don’t, I’ll redo it again.

Show 4 more comments

1

Friend, I noticed that you didn’t even call the methods of your webservice either (hello... or dowork..). Don’t forget the new 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 make the reference would be this:

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

There is a certain difference in both ways to add a reference in Visual Studio. That’s why it requires this knowledge. Then you do as I said to give the new in the reference and use your methods.

  • That, example: I have a service that I use: br.com.name.Name api = new br.com.name.Name();

  • But Advanced... > Add Web Reference... not just to add references, generating compatibility with the technology . Net Framework 2.0 Web Services?

  • Exact, but this also comes from the difference between WCF and Web Services, which can be explained here: http://www.codeproject.com/Articles/139787/What-s-the-Difference-between-WCF-and-Web-Services

  • Cool!!! : D But in his case, after I answered the first time, it’s not even the addition of the reference itself, but the test using the tool WCF Client.

  • Trying to make it work via application, now by wcf client test gives me this error: 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.