因此,今天我決定從WCF服務中刪除.svc文件,並開始在線查看。從WCF服務中刪除.svc導致沒有發現端點
這裏是一步我所做的步驟:
第1步:我加在Global.asax
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new ServiceRoute("Authorization", new WebServiceHostFactory(), typeof(Authenticator)));
RouteTable.Routes.Add(new ServiceRoute("Miscellaneous", new WebServiceHostFactory(), typeof(Misc)));
}
注:驗證器和其它都是我的接口實現
第2步:我啓用了asp.net兼容性
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
第3步:我將[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
添加到我的每個接口實現中。
第4步:我不得不將[WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest)]
添加到我的界面中的每個方法。我不知道這是幹什麼的,但是沒有它就會發生錯誤。
現在它「起作用」,但是當我導航到root/Authorization(授權是我第一個服務的名稱)時,它告訴我沒有找到端點。
我的終點在我的web.config指明爲:
<service name="AuthenticatorService.Authenticator">
<endpoint address="auth" binding="basicHttpBinding" name="AuthEndpoint"
contract="AuthInterface.IAuthenticator" />
<endpoint address="mex" binding="mexHttpBinding" name="MetadataEndpoint"
contract="IMetadataExchange" />
</service>
我很新的WCF因此它可能是一些愚蠢的錯誤。
嗯,你爲什麼要刪除.svc文件? – DOK 2012-04-01 17:25:19
因爲我讀過,你可以,我不喜歡那裏。 – TheGateKeeper 2012-04-01 17:26:30
有時,在開始試圖偏離標準實踐之前,以正常方式學習新技術會更容易。尤其是如果你沒有充分的理由選擇(不僅僅是不喜歡它)。如果你感覺固執,你可以仔細閱讀右邊的「相關」鏈接,你會發現[WCF移除.svc擴展](http://stackoverflow.com/questions/7354616/wcf-removing-svc-extention )等等。 – DOK 2012-04-01 17:33:47