2013-11-21 94 views
0

我有一個現有的WCF服務,它沒有* .SVC文件。該項目本身就是網站,並在其中編寫WCF代碼。它使用這一行註冊服務:添加服務引用不適用於沒有SVC文件的WCF服務

RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(Service1))); 

我運行從Visual Studio中的項目,並從IE檢查服務託管,並通過試驗工作方法如下:

http://localhost:51838/GetBenchMark/20 

我要創建一個使用這個WCF服務的控制檯應用程序。當我嘗試使用「添加服務引用」從Visual Studio,並給予路徑http://localhost:51838/,它是不是能夠找到它,並給出錯誤:

The HTML document does not contain Web service discovery information. 
Metadata contains a reference that cannot be resolved: 'http://localhost:51838/'. 
There was no endpoint listening at http://localhost:51838/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. 
The remote server returned an error: (404) Not Found. 
If the service is defined in the current solution, try building the solution and adding the service reference again. 

這是web.config中,如果有幫助:

<system.web> 
    <compilation debug="true" targetFramework="4.0"> 
     <assemblies> 
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     </assemblies> 
    </compilation> 
    </system.web> 
    <system.web.extensions> 
    <scripting> 
     <webServices> 
     <jsonSerialization maxJsonLength="2147483647" /> 
     </webServices> 
    </scripting> 
    </system.web.extensions> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
    </modules> 
    </system.webServer> 
    <system.serviceModel> 
    <client /> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
    <standardEndpoints> 
     <webHttpEndpoint> 
     <!-- 
      Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
      via the attributes on the <standardEndpoint> element below 
     --> 
     <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" /> 
     </webHttpEndpoint> 
    </standardEndpoints> 
    <bindings> 
     <webHttpBinding> 
     <binding closeTimeout="00:20:00" openTimeout="00:20:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" transferMode="Buffered" useDefaultWebProxy="true"> 
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     </binding> 
     </webHttpBinding> 
    </bindings> 
    </system.serviceModel> 

請讓我知道我該怎麼做才能生成代理類並開始使用控制檯應用程序中的此服務。

+0

是否有MEX端點暴露?請參閱:http://stackoverflow.com/questions/7285717/why-do-i-need-both-mex-endpoint-and-httpgetenable –

+0

不知道MEX是什麼,但我不認爲這是暴露 – CleanBold

+0

顯示您的web.config – ray

回答

0

如果您創建WCF-Service,則必須創建一個主機應用程序,但不能自行啓動此WCF-Library

如果要從主機應用程序啓動WCF服務分離,請創建一個WCF-Application。你有一個svc,你可以像你在你的問題中描述的那樣開始它。

+0

該項目是網站項目和WCF代碼寫在項目中。因此,我可以從visual studio運行/調試它。 – CleanBold

相關問題