我是新來的Silverlight編程和網絡的一般,我一直在試圖找到一個這一整天的答案。我試圖在VS2010中構建一個非常簡單的Silverlight4 Web應用程序,該應用程序在ASP.NET網站上調用Web服務(與Silverlight客戶端應用程序完全相同的解決方案,因此不應該存在任何跨域問題???)。我寫了一個使用VS'「啓用Silverlight的WCF服務的Webservice,它只是返回一個字符串。簡單的WCF Web服務從Silverlight調用(需要幫助請!)
我然後寫的代碼以消耗在Silverlight服務:))
公共的MainPage( { 的InitializeComponent(;
TestServiceClient proxy = new TestServiceClient();
EndpointAddress address = new EndpointAddress("http://localhost:" + HtmlPage.Document.DocumentUri.Port +
"/SilverlightApplication1.web/TestService.svc");
proxy.Endpoint.Address = address;
proxy.GetStringCompleted += new EventHandler<GetStringCompletedEventArgs>(proxy_GetStringCompleted);
proxy.GetStringAsync();
}
void proxy_GetStringCompleted(object sender, GetStringCompletedEventArgs e)
{
MessageBox.Show(e.Result.ToString());
}
當我從VS2010運行它時,這很好用。然而,當我把它發佈到同一臺計算機上我的個人Web服務器(IIS7),我得到一個錯誤:
網頁錯誤的詳細信息
用戶代理:Mozilla的/ 4.0(兼容; MSIE 8.0; Windows NT的6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; .NET4.0C; .NET4.0E) 時間戳:2010年五月17日,星期一08:29:51 UTC
消息:Silverlight應用程序中的未處理錯誤操作期間發生異常,導致結果無效。檢查異常詳情的InnerException。在System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() 在SilverlightApplication1.TestServiceReference1.GetStringCompletedEventArgs.get_Result() 在SilverlightApplication1.MainPage.proxy_GetStringCompleted(對象發件人,GetStringCompletedEventArgs E) 在SilverlightApplication1.TestServiceReference1.TestServiceClient.OnGetStringCompleted(對象狀態) 線:1 字符:1 代碼:0 URI:http://thunder.webhop.org:8001/home.html
當我趕在App.xaml.cs例外,我得到以下信息:
System.InvalidOperation例外:評估失敗。 在System.Windows.Browser.HtmlWindow.Eval(字符串代碼) 在 SilverlightApplication1.App.ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs E)
我應該提到的是,Web服務器,否則似乎做工精細。我可以通過端口8001在其上託管Silverlight應用程序,而不會有任何問題。我不能在我的生活中弄清楚如何進行成功的web服務調用!任何幫助將非常感謝。我浪費了整整一個下午和晚上的時間。我的心在現在圈翻轉...... :-(提前
很多很多的感謝! 運氣
PS道歉在Silverlight的論壇交叉發佈,但有一些問題存在,同時發佈。