Alojamiento WCF con dirección IP

I have created a WCF Service which return JSON data. here is my code:

namespace AppServices
{
[ServiceContract]
public interface Service1
{
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/GetCities", BodyStyle = WebMessageBodyStyle.WrappedRequest,
RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
List<City> GetCityCode();
}
[DataContract]
public class City
{
[DataMember]
public string CityId { get; set; }
[DataMember]
public string CityName { get; set; }
[DataMember]
public string StateId { get; set; }
[DataMember]
public string Priority { get; set; }
}
}

public class ServiceAPI : Service1
    {
 public List<City> GetCityCode()
        {
            adp = new SqlDataAdapter("Select * from tblCity", offcon);
            adp.Fill(ds, "City");
            var city = (from DataRow dr in ds.Tables["City"].Rows
                        select new
                        {
                            Id = dr["intCityId"].ToString(),
                            Name = dr["strTitle"].ToString(),
                            sid = dr["intStateId"].ToString(),
                            priority = dr["intPriority"].ToString()
                        }).Select(x => new City() { CityId = x.Id, CityName = x.Name, StateId = x.sid, Priority = x.priority }).ToList();

            return city;
        }
}

my web.config is as follows:

    <?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="ServiceBehaviour" name="PatrikaAPIService.PatrikaService">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding"
                  contract="PatrikaAPIService.IPatrikaService"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment/>
  </system.serviceModel>
</configuration>

Everything is working fine when i run this wcf on localhost as: localhost:13186/ServiceApp.svc/GetCities

problema: when i pass my Dirección IP as 192.168.1.16:13186/ServiceApp.svc/GetCities

it is giving an error that website is too busy... & i want to access this wcf service in URL on other computers i mean other PCs on my Network. I have changed my web.config as per my requirements now if anyone know what to do next to host this service with IP address. or Host this into Microsoft 2003 Server SP2. please help..

preguntado el 31 de julio de 12 a las 11:07

What http response are you getting? Is it a 500 (Server busy)? -

no it is giving can't establish a connection to the server.. but well worked with localhost... please see my edited question.. -

then most probably the IP address in the url is not correct. -

No i have checked it it is correct. -

By default the port should not be listening for any http traffic. When you use your IP address your traffic is sent to port 80 on IIS which has the http port mapped. Try using netsh and map the 13186 to http port and then see if it works -

1 Respuestas

I'm assuming this is Cassini? If so - Cassini only responds if the host header is 'localhost' I think. Certainly you won't get it to respond by your IP.

Host it in IIS or IIS Express.

On a different note - if this is a .Net 4 project you might be interested to note that Rest services implemented this way via WCF is soon to become legacy - and be replaced by the API web de Asp.Net once it's gone to RTM (it's currently at RC stage) - I urge you to consider this newer technology if you can (it wouldn't solve this issue though).

Respondido 31 Jul 12, 11:07

and how to do that as i dont know much about it. act. i am quite new with this technology... - Abhishek Mathur

Problem solved after host this service in IIS actually in my case it is taking ASP.NET framework Pool of Classic and i was trying to do it with integrated mode. - Abhishek Mathur

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.