我試圖從WCF服務的URL使用下面的代碼來獲得JSON:轉換WCF休息
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "players")]
public List<Person> GetResult()
{
List<Person> results = new List<Person>();
results.Add(new Person("Peyton", "Manning", 35));
results.Add(new Person("Drew", "Brees", 31));
results.Add(new Person("Tony", "Romo", 29));
return results;
}
我web.config
:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
<httpModules>
<add name="ApplicationInsightsWebTracking"
type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
------
</system.webServer>
</configuration>
但是當我開始調試WCF服務,瀏覽到
http://localhost:55636/Service1.svc/players
我得到一個空白頁 - 爲什麼?我該怎麼做,也許我需要轉換WCF休息?
您使用的是哪種瀏覽器? IE例如開始下載json文件並顯示空白頁面。你能不能發佈你的web.config? – MadOX
Firefox和Chrome返回空白頁,我沒有測試IE –
你有沒有檢查過檢查員?特別是在回覆標籤中,你回來了什麼? –