WCF service hosting with endpoint creation?

Asked

Viewed 136 times

1

I noticed that when running a Rest type project when opening the interface, opens the internet browser is lists all the contents of the folder, being necessary to select the ".svc" when running the ".svc" and open a WCF Test Client screen, Is there any settings to open at the correct address? My "web.config" is like this:

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

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5" />
  </system.web>


  <system.serviceModel>

    <!--Adicionado -->
    <services>
      <service name="WcfRest.BookService">

        <endpoint address="" binding="webHttpBinding" contract="WcfRest.IBookService"  behaviorConfiguration="restfulBehavior" >
        </endpoint>

        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:3951/WcfRest/BookService.svc" />
          </baseAddresses>
        </host>


      </service>  
    </services>

    <!--Adicionado --> 

    <behaviors>

      <endpointBehaviors>
        <behavior name="restfulBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>

      <!--Adicionado -->

      <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" />
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true" />
  </system.webServer>

  <connectionStrings>
    <add name="SERRESTEEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=\SQLEXPRESS;initial catalog=SERRESTE;persist security info=True;user id=sa;password=**;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

  • The "correct address" is exactly what ends with ". svc". What you want exactly?

  • Friend, in my question I say what I need, I appreciate the help!

1 answer

0


Wcftestclient does not work to access WCF REST services. When you point Wcftestclient to a service, it attempts to access the Metadata endpoint of the service, which describes all operations, and Binding that needs to be used to access it. WCF-supported media formats (WSDL and WS-Metadata) are used to describe SOAP services, not REST, so the test client will not be able to consume your REST service, since he does not know how to do it.

Note that it may even be that some operation works - if you ask a WCF service for its Terminal, it will make a "better effort" to respond. But in general, operations cannot be accessed by test client.

If you want to know more, the post on http://blogs.msdn.com/b/carlosfigueira/archive/2012/03/26/mixing-add-service-reference-and-wcf-web-http-a-k-a-rest-endpoint-does-not-work.aspx describes in more detail what I mentioned above.

  • Friend, all operations are working, my doubt may not have been clear, but it is about execution, when the execution of the service is done it opens in a different way, as seen in the images, if executed in the interface opens the internet browser and lists all files in the folder.

  • If running from ".svc" opens a WCF Test Client, so I posted web.config, I want to know what I need to configure for the service open the correct page.

  • To open when you do "F5" in Visual Studio? If so, go to your project properties, select "Current Page" (I have the English version), and select the page you want to open (Bookservice.svc).

  • I think that’s it! I’ll try!

Browser other questions tagged

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