2011-03-21 84 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>