2014-01-08 56 views
0

我在解決方案中有一個web應用程序項目和silverlight項目。我在web應用程序WCF文件,我也得到了下面的錯誤,而更新的ServiceReference無法更新ServiceReference或刪除後再次添加?

There was an error downloading 'http://localhost:5678/DataForSilverlight.svc/_vti_bin/ListData.svc/$metadata'. 
The request failed with HTTP status 404: Not Found. 
Metadata contains a reference that cannot be resolved: 'http://localhost:5678/DataForSilverlight.svc'. 
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error. 
If the service is defined in the current solution, try building the solution and adding the service reference again. 

我也試圖將其刪除,然後重新添加,而且我也嘗試從Web應用程序刪除WCF文件。

+0

你可能會在解決方案Silverlight項目而不是服務:http://本地主機:5678/DataForSilverlight.svc。要添加服務,必須啓動並運行 –

+0

我還添加了DataForSilverlight.svc。以前它運行良好,但在對svc文件進行一些更改後,iam無法更新,我已經檢查了svc文件代碼中的所有內容,並且一切都很好,但它給出了上述錯誤 –

+0

刪除服務,執行「clean project」 。再次添加。您有可能更改的端口號。 –

回答

0

當您使用動態端口通過IIS公開Web應用程序(然後是WCF服務)時,通常會發生此錯誤,該錯誤每次啓動和停止解決方案的調試時都會更改。

要避免此問題,請右鍵單擊Web項目並選擇「屬性」。選擇標籤'Web'。在名爲「服務器」的組框中,插入所需的網絡路徑,然後單擊「創建虛擬目錄」按鈕。 IIS將爲您的Web項目創建一個虛擬目錄。

enter image description here

現在,您可以爲您服務引用添加到Silverlight項目。下次執行Web項目時,IIS將使用所需的網絡路徑執行Web應用程序。

此外,確保在您的服務類定義以下屬性聲明:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
public class DataForSilverlight 

和下面一行是存在於你的web.config文件中,<system.serviceModel>部分:

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
+0

它仍然給出同樣的錯誤 –

+0

@ GeneliaD'Souza我更新了答案。 –

+0

是的,我再次檢查上述仍然相同的錯誤 –

0

不知道爲什麼,但我又在這是befor改變方法改變的變量類型

[OperationContract] 
     void SaveData(int UserId, string FileName, ExtendedImage File); 

後來改成了字符串

[OperationContract] 
     void SaveData(int UserId, string FileName, string File); 

,一切工作正常,現在

+1

看起來很奇怪,像這樣的改變是WCF服務的404錯誤的責任。作爲建議,爲避免誤解,最好編寫一個不是類名的變量名。例如,最好在'字符串文件'中替換變量'string File'。無論如何,你解決了這個問題。 –

+0

我傳遞一個外部庫的對象作爲WCF中的方法的一個參數:p ExtendedImage就是上面的例子@AlbertoSolano –

相關問題