2011-03-21 85 views
1

我正在做一個概念驗證,其中從我的Silverlight 4客戶端應用程序訪問公共Web服務。當我嘗試撥打電話牛逼his sample public web service,我得到以下錯誤:從Silverlight 4客戶端訪問SOAP Web服務

An error occurred while trying to make a request to URI 'http://www.w3schools.com/webservices/tempconvert.asmx'. 
This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, 
or a policy that is unsuitable for SOAP services. 
You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. 
This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details. 

我只能具有制訂了這些政策或者是接入網絡服務我根本就沒有正確地在我的項目配置我的ASMX服務?調用服務的代碼如下:

// Create 
    var webServiceProxy = new TempConvert.TempConvertSoapClient(); 

    // Delegate 
    webServiceProxy.FahrenheitToCelsiusCompleted += (s, args) => 
    { 
     // Fail? 
     if (args.Error != null) 
     { 
      // Message 
      MessageBox.Show(string.Format("Something went wrong!\n\n{0}", args.Error.Message)); 
     } 
     else 
     { 
      // Message 
      MessageBox.Show(string.Format("50 f to c is {0}.", args.Result)); 
     } 
    }; 

    // Call 
    webServiceProxy.FahrenheitToCelsiusAsync("50"); 

回答

2

最有可能的,如果你從你的機器上運行這個,你穿越域邊界,並要求網站名爲到位,從打電話到有政策不同的域。

Microsoft has plenty of information about it,同時查看'silverlight cross domain'以獲取更多信息。

+0

我覺得是這樣的話,但似乎非常嚴格,我不能設置一個政策在我的客戶端允許連接到另一個域,儘管它沒有訪問策略。這將排除直接從Silverlight客戶端訪問大量第三方Web服務的可能性。 – 2011-03-21 20:42:52

+0

那麼你可以嘗試從瀏覽器(OOB)運行silverlight。在Visual Studio 2010中,右鍵單擊Silverlight項目 - >單擊屬性 - >單擊Silverlight選項卡(如果尚未存在)。單擊「使運行中的應用程序脫離瀏覽器」旁邊的複選框。通過OOB設置按鈕修改它的任何設置(寬度/高度,啓用提升的信任。)。運行你的程序。這應該給你提升權限並讓你通過域名政策。 – Landern 2011-03-22 16:34:09

1

當服務器URL收到get = /clientaccesspolicy.xml 確保它的答案:

<access-policy> 
      <cross-domain-access> 
       <policy> 
        <allow-from http-request-headers="*"> 
         <domain uri="*"/> 
        </allow-from> 
        <grant-to> 
         <resource path="/" include-subpaths="true"/> 
        </grant-to> 
       </policy> 
      </cross-domain-access>