【问题标题】:Not able to access WCF Rest method hosted in IIS 7 remotely or locally无法远程或本地访问托管在 IIS 7 中的 WCF Rest 方法
【发布时间】:2013-11-29 18:41:38
【问题描述】:

我的问题看起来与此线程中讨论的问题相似 Checked this thread and went through all the steps but my problem exists

直接从 Visual Studio 运行服务,我可以使用 http://localhost:12827/HighONDealsService/GetDeals/43.1656/-77.6114 调用 REST WebGet 方法,但是在远程服务器上的 IIS 中部署我的服务后,我无法再访问 WebGet 方法了。

我的服务可以在这里看到http://155.98.38.135:12827/HighONDealsService.svc

我可以访问该服务,甚至可以访问该服务的帮助页面,但无法访问实际的服务方法http://155.98.38.135:12827/HighONDealsService/help

我的实际服务目录对网络服务和 IIS_IUSRS 具有读取和执行权限。

我的 Global.asax.cs 文件看起来像

protected void Application_Start(object sender, EventArgs e)
    {
        RouteTable.Routes.Add(new ServiceRoute("HighONDealsService", new WebServiceHostFactory(), typeof(HighONDealsService)));
    }

我尝试了上述线程中的步骤,但无济于事 这是我的 web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionGroup name="system.serviceModel"    type="System.ServiceModel.Configuration.ServiceModelSectionGroup, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="standardEndpoints" type="System.ServiceModel.Configuration.StandardEndpointsSection, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        </sectionGroup>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </configSections>

    <system.web>
        <compilation debug="true" targetFramework="4.5">
            <assemblies>
                <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            </assemblies>
        </compilation>
        <pages controlRenderingCompatibilityVersion="4.0" />
        <identity impersonate="false" />
        <authentication mode="Windows" />
    </system.web>

    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true">      
        </serviceHostingEnvironment>
        <standardEndpoints>
            <webHttpEndpoint>
                <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"></standardEndpoint>
            </webHttpEndpoint>
        </standardEndpoints>
    </system.serviceModel>

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
        <directoryBrowse enabled="true" />
    </system.webServer>

    <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
        <providers>
            <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
    </entityFramework>

    <connectionStrings><add name="DataContext" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=PC535\SQLEXPRESS;initial catalog=CSharpTeamProject;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>
</configuration>

实际服务实现:

/// <summary>
/// 
/// </summary>
[ServiceContract]
public interface IHighONDealsService
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="userLat"></param>
    /// <param name="userLong"></param>
    /// <returns></returns>
    [OperationContract]
    [WebGet(UriTemplate = "GetDeals/{userLat}/{userLong}")]
    List<DealObject> GetDeals(string userLat, string userLong);        
}

/// <summary>
/// 
/// </summary>
[DataContract]
public class DealObject
{
    [DataMember]
    public string City;

    [DataMember]
    public string Category;

    [DataMember]
    public string SearchResult;

    [DataMember]
    public decimal Latitude;

    [DataMember]
    public decimal Longitude;

    [DataMember]
    public string Deals;

    [DataMember]
    public string Address;
}

从 Visual Studio 实例运行的服务的 Fiddler Trace 显示完整的 xml 响应 &lt;ArrayOfDealObject xmlns="http://schemas.datacontract.org/2004/07/HighONDealsService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;&lt;DealObject&gt;&lt;Address i:nil="true"/&gt;&lt;Category&gt;Bars&lt;/Category&gt;&lt;City&gt;Rochester&lt;/City&gt;&lt;Deals&gt;Stay late and get drunk - free drinks on the house after 10pm&lt;/Deals&gt;&lt;Latitude&gt;43.160850&lt;/Latitude&gt;&lt;Longitude&gt;-77.601294&lt;/Longitude&gt;&lt;SearchResult&gt;Tavern 58 At Gibbs&lt;/SearchResult&gt;&lt;/DealObject&gt;&lt;DealObject&gt;&lt;Address i:nil="true"/&gt;&lt;Category&gt;Hospital&lt;/Category&gt;&lt;City&gt;Rochester&lt;/City&gt;&lt;Deals&gt;Get your pet checked up for free all winter long&lt;/Deals&gt;&lt;Latitude&gt;43.176582&lt;/Latitude&gt;&lt;Longitude&gt;-77.551338&lt;/Longitude&gt;&lt;SearchResult&gt;Laurelton Animal Hospital&lt;/SearchResult&gt;&lt;/DealObject&gt;&lt;DealObject&gt;&lt;Address i:nil="true"/&gt;&lt;Category&gt;Airport&lt;/Category&gt;&lt;City&gt;Rochester&lt;/City&gt;&lt;Deals&gt;Enjoy your stay with complimentary spa sessions&lt;/Deals&gt;&lt;Latitude&gt;43.130763&lt;/Latitude&gt;&lt;Longitude&gt;-77.668665&lt;/Longitude&gt;&lt;SearchResult&gt;Fairfield Inn Rochester Airport&lt;/SearchResult&gt;&lt;/DealObject&gt;&lt;DealObject&gt;&lt;Address i:nil="true"/&gt;&lt;Category&gt;Pizza&lt;/Category&gt;&lt;City&gt;Rochester&lt;/City&gt;&lt;Deals&gt;Get 1 large Pizza with every Sheet Pizza&lt;/Deals&gt;&lt;Latitude&gt;43.138420&lt;/Latitude&gt;&lt;Longitude&gt;-77.594986&lt;/Longitude&gt;&lt;SearchResult&gt;Salvatore's Pizzeria&lt;/SearchResult&gt;&lt;/DealObject&gt;&lt;DealObject&gt;&lt;Address i:nil="true"/&gt;&lt;Category&gt;Restaurants&lt;/Category&gt;&lt;City&gt;Rochester&lt;/City&gt;&lt;Deals&gt;Dollar 5 discount on every takeaway&lt;/Deals&gt;&lt;Latitude&gt;43.153626&lt;/Latitude&gt;&lt;Longitude&gt;-77.608005&lt;/Longitude&gt;&lt;SearchResult&gt;Dinosaur Barbeque&lt;/SearchResult&gt;&lt;/DealObject&gt;&lt;DealObject&gt;&lt;Address i:nil="true"/&gt;&lt;Category&gt;Bars&lt;/Category&gt;&lt;City&gt;Rochester&lt;/City&gt;&lt;Deals&gt;Happy hours all this month&lt;/Deals&gt;&lt;Latitude&gt;43.119709&lt;/Latitude&gt;&lt;Longitude&gt;-77.619911&lt;/Longitude&gt;&lt;SearchResult&gt;Sheridan's Pub&lt;/SearchResult&gt;&lt;/DealObject&gt;&lt;DealObject&gt;&lt;Address i:nil="true"/&gt;&lt;Category&gt;Gas Station&lt;/Category&gt;&lt;City&gt;Rochester&lt;/City&gt;&lt;Deals&gt;Get 3 car washes for dollar 10 only&lt;/Deals&gt;&lt;Latitude&gt;43.138942&lt;/Latitude&gt;&lt;Longitude&gt;-77.669807&lt;/Longitude&gt;&lt;SearchResult&gt;Anthony's Sunoco&lt;/SearchResult&gt;&lt;/DealObject&gt;&lt;/ArrayOfDealObject&gt;

但是 IIS 中托管的服务的 Fiddler Trace 显示空白 &lt;ArrayOfDealObject xmlns="http://schemas.datacontract.org/2004/07/HighONDealsService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/&gt;

我在这里做错了什么?

【问题讨论】:

    标签: c# wcf rest iis-7 webget


    【解决方案1】:

    问题似乎在于实体框架连接到后端的 Windows 身份验证/集成安全性。正在努力:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多