2013-02-17 121 views
1

我已經使用WCF服務應用程序模板在Visual Studio 2012中創建了一個Web服務。無法將Web服務引用添加到mvc 4項目

一切工作正常,但只有當主機機應用相同的解決方案裏面,你可以在這個圖片中看到:

  • Bank項目是Web服務
  • BankHost項目是Windows窗體項目

enter image description here

,但是當我試圖從A獲得參考服務SP.NET MVC 4項目我得到這個錯誤:

enter image description here

這是web.config文件的Web服務項目

<configuration> 
    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5"/> 
    </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> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <directoryBrowse enabled="true"/> 
    </system.webServer> 
</configuration> 

這是我web.config文件中的MVC 4項目的:

<configuration> 
    <configSections> 
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
     <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> 
     <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> 
    </sectionGroup> 
    </configSections> 
    <system.web.webPages.razor> 
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    <pages pageBaseType="System.Web.Mvc.WebViewPage"> 
     <namespaces> 
     <add namespace="System.Web.Mvc" /> 
     <add namespace="System.Web.Mvc.Ajax" /> 
     <add namespace="System.Web.Mvc.Html" /> 
     <add namespace="System.Web.Optimization"/> 
     <add namespace="System.Web.Routing" /> 
     </namespaces> 
    </pages> 
    </system.web.webPages.razor> 
    <appSettings> 
    <add key="webpages:Enabled" value="false" /> 
    </appSettings> 
    <system.web> 
    <httpHandlers> 
     <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/> 
    </httpHandlers> 
    <pages 
     validateRequest="false" 
     pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
     pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
     userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
     <controls> 
     <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" /> 
     </controls> 
    </pages> 
    </system.web> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <handlers> 
     <remove name="BlockViewHandler"/> 
     <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /> 
    </handlers> 
    </system.webServer> 
</configuration> 
+1

讓我們瞭解一些遺漏的細節; 1.當您添加服務並列出正確的端口時,該服務當前正在運行?即。它與IISexpress/web服務器報告一樣嗎? – f0x 2013-02-17 20:58:03

+0

你爲什麼使用Web引用? – 2013-02-18 02:02:30

回答

1

檢查您的.svc文件 - 它是否有HostingFactory屬性?

Factory="WebApplication1.MyServiceHostFactory" 

工廠的名稱是Your service name + HostFactory和整個路徑是實際的命名空間,在這裏你.svc文件的位置。

+0

右鍵單擊Service.svc - >查看標記 – user1310492 2013-02-17 21:07:58

+0

給了我這個 <%@ ServiceHost Language =「C#」Debug =「true」Service =「Bank.MainClass」CodeBehind =「Service.svc.cs」%> – user1310492 2013-02-17 21:08:37

+0

嘗試添加Factory =「Bank.MainClassHostFactory」 – d1mitar 2013-02-17 21:10:16

相關問題