我有一個MVC項目,我已經在根目錄中添加了一個名爲WCF的文件夾。在此文件夾中,我創建了一個名爲CustomFunctions
的WCF服務。當我嘗試啓動我收到以下錯誤的服務:在區域之外的MVC應用程序中託管WCF服務
Error: Cannot obtain Metadata from
http://localhost/Viper/WCF/CustomFunctions.svc
... Metadata contains a reference that cannot be resolved:
有了額外的描述:
The type 'Viper.WCF.CustomFunctions', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
昨天我得到這個錯誤,並花了一些時間在網上淘了一個答案。這導致我對Web.config和Global.asax.cs進行了很多更改。昨天一點,它開始工作,我停了下來。但是,當我今天早上回來時,它並沒有重新工作。沒有添加任何新內容,並且在此期間沒有任何代碼被更改。
我加入以下到我的web.config:
<system.serviceModel>
<services>
<service behaviorConfiguration="WCFBehavior" name="Viper.WCF.CustomFunctions">
<endpoint address="" binding="wsHttpBinding" contract="Viper.WCF.ICustomFunctions">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/Viper/WCF/CustomFunctions/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" httpGetUrl=""/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
這對我Global.asax.cs
:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.svc/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}, // Parameter defaults
new { controller = "^(?!CustomFunctions).*" }
);
routes.Add(new ServiceRoute("CustomFunctions", new ServiceHostFactory(),
typeof(CustomFunctions)));
}
誰能幫助我?我在這裏完全沒有想法。
我不確定這是可行的(儘管我懷疑它是這樣),但是有沒有一些原因讓你不想有不同的路徑?我們的MVC應用程序還使用了一個WCF服務,我在同一個應用程序池中託管,但由於您現在面臨的複雜情況,我只是選擇不採取這種方式,並沒有令人信服的理由讓事情比他們需要的更加困難是...但是如果有人發佈它,我會對解決方案感興趣... – Pete
你看過嗎? http://stackoverflow.com/questions/4047485/expose-wcf-services-that-belong-to-an-area-in-mvc-app-at-a-routed-path – Pete
我已經看過那篇文章關於路線並進行必要的更改,如我發佈的Global.asax.cs代碼中所示。我們希望將WCF服務放入我們的MVC項目的原因是我們不希望在兩個項目之間分開使用緩存。我們只想要一個。我的主管想讓我試着讓這個表演很好。但是,如果我不快速計算出某些東西,我可能會隨單獨的項目一起去,因爲我知道它在我的WCF項目之外的MVC中工作。 –