2011-02-24 52 views
4

我們正在構建Silverlight應用程序並調用Silverlight-WCF服務。從Visual Studio運行應用程序時,一切正常。當我們部署到網站並運行應用程序時,每次調用Web服務時都會收到以下錯誤(或者非常喜歡它)。Silverlight webservice調用在Studio中工作,但在從網站運行時失敗

Message: Unhandled Error in Silverlight Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() 
    at SSS.MVVMCore.Silverlight.WebPortalService.GetThemeIdCompletedEventArgs.get_Result() 
    at SSS.MVVMCore.Silverlight.ViewModels.StandardBaseFrameViewModel.<.ctor>b__0(Object s, GetThemeIdCompletedEventArgs ea) 
    at SSS.MVVMCore.Silverlight.WebPortalService.WebPortalServiceClient.OnGetThemeIdCompleted(Object state) 
Line: 1 
Char: 1 
Code: 0 
URI: http://ssswebportal.com/login.aspx?p=d53ae99b-06a0-4ba7-81ed-4556adc532b2 

基於他的消息,該服務被稱爲完全執行,但是,當它試圖反序列化的結果早在Silverlight應用程序出現錯誤。對於正在發生的事情以及我們可以採取哪些措施來解決問題有任何建議?

< < < < < < < < < < < < < < < < < < < < < < < < < < < <跟進>>>>>>>>>>>>>>> >>>>>>>>>>>>>

這是我們的決議:

在ServiceReferences.ClientConfig文件,我們有下面的代碼:

<client> 
    <endpoint address="http://localhost:5482/WebPortalService.svc" 
     binding="customBinding" bindingConfiguration="CustomBinding_WebPortalService" 
     contract="WebPortalService.WebPortalService" name="CustomBinding_WebPortalService" /> 
</client> 

注意 'localhost' 的線。它在發佈時需要成爲我們的Web服務器地址,但在開發時需要成爲本地主機。

人對如何自動完成這個任何建議,讓我們沒有之前手動更改此行每發佈嗎?

+1

您應該能夠通過傳遞的EndpointAddress並沒有回答關於ServiceReferences.ClientConfig設置的配置對象綁定到在代碼中創建您的服務代理。也許你可以自己管理端點的配置,並使用某種#if DEBUG替換localhost。 – 2011-02-24 17:49:41

回答

2

有兩件事你需要做。

首先,在網站上提供clientaccesspolicy.xml and/or crossdomain.xml文件。 This MSDN article有詳細信息。我也發現this blog entry是有用的。

其次,確保您的服務參考端點指向正確的URL。對於我的項目,我有不同的構建配置(發佈,調試,測試,測試等)和幾個端點。然後我在代碼中使用#if指令選擇適當的端點。

例如:

soapClient = 
#if DEBUG 
     new MySoapClient("DebugService"); 
#elif TESTRELEASE 
     new MySoapClient("TestService"); 
#elif BETA 
     new MySoapClient("BetaService"); 
#else 
     new MySoapClient("ReleaseService"); 
#endif 
+0

這給了我們一個開始的好地方,請閱讀我的後續內容,看看我們如何解決此問題以供將來參考。 – ErocM 2011-02-24 16:57:02

+0

@ErocM:我已經更新了我的答案,以反映您的問題所做的更改。謝謝。 – 2011-02-24 18:22:22

0

當WCF服務部署在不同的領域中對於應用程序的位置這通常發生。如果這是一個臨時的情況,那麼在同一個域中的服務和應用程序將解決。如果無法爲應用程序上的遠程服務創建代理,則可以使用該代理。

相關問題