无法远程或本地访问IIS 7中托管的WCF Rest方法

时间:2013-11-29 18:41:39

标签: c# wcf rest iis-7 webget

我的问题看起来类似于此主题中讨论的问题 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方法了。 / p>

我的服务可以在http://155.98.38.135:12827/HighONDealsService.svc

看到

我能够访问该服务,甚至是服务的帮助页面,但不是实际的服务方法http://155.98.38.135:12827/HighONDealsService/help

我的实际服务目录有Read&执行网络服务和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响应<ArrayOfDealObject xmlns="http://schemas.datacontract.org/2004/07/HighONDealsService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><DealObject><Address i:nil="true"/><Category>Bars</Category><City>Rochester</City><Deals>Stay late and get drunk - free drinks on the house after 10pm</Deals><Latitude>43.160850</Latitude><Longitude>-77.601294</Longitude><SearchResult>Tavern 58 At Gibbs</SearchResult></DealObject><DealObject><Address i:nil="true"/><Category>Hospital</Category><City>Rochester</City><Deals>Get your pet checked up for free all winter long</Deals><Latitude>43.176582</Latitude><Longitude>-77.551338</Longitude><SearchResult>Laurelton Animal Hospital</SearchResult></DealObject><DealObject><Address i:nil="true"/><Category>Airport</Category><City>Rochester</City><Deals>Enjoy your stay with complimentary spa sessions</Deals><Latitude>43.130763</Latitude><Longitude>-77.668665</Longitude><SearchResult>Fairfield Inn Rochester Airport</SearchResult></DealObject><DealObject><Address i:nil="true"/><Category>Pizza</Category><City>Rochester</City><Deals>Get 1 large Pizza with every Sheet Pizza</Deals><Latitude>43.138420</Latitude><Longitude>-77.594986</Longitude><SearchResult>Salvatore's Pizzeria</SearchResult></DealObject><DealObject><Address i:nil="true"/><Category>Restaurants</Category><City>Rochester</City><Deals>Dollar 5 discount on every takeaway</Deals><Latitude>43.153626</Latitude><Longitude>-77.608005</Longitude><SearchResult>Dinosaur Barbeque</SearchResult></DealObject><DealObject><Address i:nil="true"/><Category>Bars</Category><City>Rochester</City><Deals>Happy hours all this month</Deals><Latitude>43.119709</Latitude><Longitude>-77.619911</Longitude><SearchResult>Sheridan's Pub</SearchResult></DealObject><DealObject><Address i:nil="true"/><Category>Gas Station</Category><City>Rochester</City><Deals>Get 3 car washes for dollar 10 only</Deals><Latitude>43.138942</Latitude><Longitude>-77.669807</Longitude><SearchResult>Anthony's Sunoco</SearchResult></DealObject></ArrayOfDealObject>

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

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

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