Search code examples
c#wcfwcf-binding

Defining baseURL and EndPoint


I made a WCF with three methods:

[ServiceContract]
public interface IService1
{
    [OperationContract]
    String devolverPisosA();

    [OperationContract]
    String devolverPisosV();

    [OperationContract]
    String devolverNoticias();
}

I need to define baseAddress and EndPoint in Web.config file but I don´t know how:

I´m trying this (and some variations) but this is not working... (between system.serviceModel)

<services>
      <service
       name="ProyectoJosephWCF.Service1">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000/Iservice1/"/>
          </baseAddresses>
        </host>

    <endpoint address="devolverPisoA"
                 binding="wsHttpBinding"
                 contract="ProyectoJosephWCF.Service1" />
    <endpoint address="devolverPisoV"
                 binding="wsHttpBinding"
                 contract="ProyectoJosephWCF.Service1" />
    <endpoint address="devolverNoticias"
                 binding="wsHttpBinding"
                 contract="ProyectoJosephWCF.Service1" />

  </service>
</services>

EDITED: If I´m not defining the baseAddress and endpoint before (using default configuration which was created when I created the project), and I launched the Services1.svc, I can reach the result json through testing windows but I can´t (or at least I don´t know how) to reach that JSON result from Android (by Retrofit). I supposed that I configured Retrofit (baseAddress and Endpoint values wrong), so I decided to set those values by my own... For that I set the code before in Web.config, but I can´t reach them as well...

Beside, I would like to reach JSON result by Mozilla (in browser I mean), because someone said me that could me help to understand what baseAddress and Endpoint I´m using...

EDITED2: Behaviors are settings as:

<behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

And still don´t reach result by android or browser...


Solution

  • Finally... Check it out if you need it.

    <behaviors>
      <serviceBehaviors>
    
        <behavior name="ServiceBehavior" >
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
    
    
        <behavior>
          <!-- 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>
    

    And:

            [OperationContract]
            [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "devolverPisoA")]
            List<pisosAlquiler> devolverPisosA();