2015-09-17 55 views
0

我想在我的web應用程序中託管一個svc服務,我試圖用一個簡單的客戶端應用程序連接到它。添加服務引用只適用於本地主機wcf服務

當主機在我自己的電腦和解決方案主辦,我在本地運行Web應用程序,一切工作正常,這意味着我可以參考添加到我的客戶端解決方案使用add service referencehttp://localhost:6543/Hello.svc的地址和服務當我導航到服務的URL時,它會顯示服務的信息。

但是,當我發表我的網站,我嘗試參考使用add service referencehttp://myserver.com/Hello.svc添加到我服務的地址,我得到錯誤信息bleow:

There was an error downloading ' http://myserver.com/Hello.svc/_vti_bin/ListData.svc/ $metadata'. The request failed with HTTP status 404: Not Found. Metadata contains a reference that cannot be resolved: ' http://myserverc.com/Hello.svc '. The remote server returned an unexpected response: (405) Method Not Allowed. The remote server returned an error: (405) Method Not Allowed. If the service is defined in the current solution, try building the solution and adding the service reference again.

和奇怪的是,當我瀏覽到myserver.com/Hello.svc瀏覽器開始下載Hello.svc文件,而不是顯示服務的詳細信息和信息。

這是我的網站的web.config文件:

<system.serviceModel> 
    <bindings> 
     <webHttpBinding> 
     <binding name="crossDomain" crossDomainScriptAccessEnabled="true" /> 
     </webHttpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WithDebug"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    <services> 
     <service name="HelloWorldService.HelloService" behaviorConfiguration="WithDebug"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://myserver/Hello.svc"/> 
      </baseAddresses> 
     </host> 
     <endpoint 
      address="" 
      binding="webHttpBinding" bindingConfiguration="crossDomain" 
      contract="HelloWorldService.IHelloWorld" /> 
     <endpoint 
      address="mex" 
      binding="mexHttpBinding" 
      contract="IMetadataExchange" /> 
     </service> 
    </services> 
    </system.serviceModel> 

我想我失去了一些東西在這裏大,但由於我是新來的WCF,我不知道這是什麼is.Any幫助將不勝感激和如果需要,我很樂意發佈有關我的項目的更多詳細信息。

在此先感謝

+0

您正在使用哪個版本的Windows Server?你有其他的Wcf應用程序在同一臺服務器上運行嗎? –

+0

我正在使用運行Windows Server 2008和.net版本4.0的主機服務器。並且不,這是我嘗試在此服務器上運行的第一個服務。是否該服務器不支持WCF? – roostaamir

+1

也許你的服務器沒有安裝框架/ wcf激活。 您會看到以下鏈接以證明您的服務器正常:http://blogs.msdn.com/b/blambert/archive/2009/02/13/enable-iis.aspx 您也可以在服務器上進行本地測試,如果頁面打開。在IIS管理器上嘗試瀏覽Hello.svc文件 –

回答

0

你需要運行ServiceModel registration tool

「此命令行工具提供了管理一臺機器上的WCF和WF組件的註冊的能力。在正常情況下,你不應該需要因爲WCF和WF組件是在安裝時配置的,但如果遇到服務激活問題,可以嘗試使用此工具註冊組件。

相關問題