【发布时间】:2012-07-29 02:33:53
【问题描述】:
我创建了一个返回 JSON 数据的 WCF 服务。 这是我的代码:
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如下:
<?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
问题: 当我将我的 IP 地址 传递为 192.168.1.16:13186/ServiceApp.svc/GetCities
它给出了一个错误,即网站太忙... &我想在其他计算机上的 URL 中访问此 wcf 服务,我的意思是我网络上的其他 PC。 如果有人知道接下来要做什么来使用 IP 地址托管此服务,我现在已根据我的要求更改了我的 web.config。 或将其托管到 Microsoft 2003 Server SP2 中。 请帮忙..
【问题讨论】:
-
你得到了什么http响应?是 500(服务器忙)吗?
-
不,它无法建立与服务器的连接.. 但与 localhost 合作得很好......请查看我编辑的问题..
-
那么很可能是url中的IP地址不正确。
-
不,我检查过它是正确的。
-
默认情况下端口不应该监听任何http流量。当您使用您的 IP 地址时,您的流量将发送到 IIS 上的端口 80,该端口映射了 http 端口。尝试使用netsh并将13186映射到http端口,然后看看它是否有效
标签: wcf localhost ip-address