EliasMP EliasMP - 2 months ago 13
C# Question

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

Answer

You need to set httpGetEnabled="true" for having WSDL available like below

<behaviors>
 <serviceBehaviors>
  <behavior name="NewBehavior">
    <serviceMetadata httpGetEnabled="true" />
  </behavior>
 </serviceBehaviors>
</behaviors>

Include the same behavior configuration in your service declaration like

      <service name="ProyectoJosephWCF.Service1"
behaviorConfiguration="NewBehavior">

See serviceMetadata for more information.