使用IP地址的WCF托管 [英] WCF Hosting with IP Address

查看:61
本文介绍了使用IP地址的WCF托管的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个WCF服务,该服务返回JSON数据. 这是我的代码:

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;
        }
}

我的web.config如下:

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>

当我在localhost上以以下方式运行此wcf时,一切工作正常: 本地主机:13186/ServiceApp.svc/GetCities

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

问题:当我以以下方式通过我的 IP地址时: 192.168.1.16:13186/ServiceApp.svc/GetCities

problem: when i pass my IP address as 192.168.1.16:13186/ServiceApp.svc/GetCities

出现错误,表明网站太忙了... &我想在其他计算机上的URL中访问此wcf服务,我的意思是网络上的其他PC. 如果有人知道下一步如何使用IP地址托管此服务,则我已根据我的要求更改了web.config. 或将其托管到Microsoft 2003 Server SP2中. 请帮忙.

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

推荐答案

我假设这是卡西尼(Cassini)吗?如果是这样,我认为Cassini仅在主机头为"localhost"时响应.当然,您不会让它通过IP进行响应.

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.

将其托管在IIS或IIS Express中.

Host it in IIS or IIS Express.

另一点说明-如果这是一个.Net 4项目,您可能会感兴趣地注意到,通过WCF以这种方式实现的Rest服务很快将成为传统-并由

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 Asp.Net Web API 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).

这篇关于使用IP地址的WCF托管的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆