C# 从Silverlight 4客户端访问SOAP web服务

C# 从Silverlight 4客户端访问SOAP web服务,c#,silverlight-4.0,webservices-client,C#,Silverlight 4.0,Webservices Client,我正在进行概念验证,从Silverlight 4客户端应用程序访问公共web服务。当我尝试调用t时,我得到以下错误: 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 wit

我正在进行概念验证,从Silverlight 4客户端应用程序访问公共web服务。当我尝试调用t时,我得到以下错误:

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.
我是否只能访问具有这些策略的web服务,或者我只是没有在项目中正确配置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");

最有可能的情况是,如果您是从您的计算机上运行此操作,则您正在跨越域边界,并要求被调用的站点具有从其他域调用的策略


,还可以查找“silverlight cross domain”以了解更多信息。

当服务器收到带有url=/clientaccesspolicy.xml的GET时 确保它符合以下要求:

<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>


我认为是这样的,但我无法在客户端中设置允许连接到另一个域的策略(尽管它没有访问策略),这似乎有很大的限制。这将排除直接从Silverlight客户端访问许多第三方web服务的可能性。您可以尝试在浏览器外运行Silverlight(OOB)。在VisualStudio2010中,右键单击Silverlight项目->单击属性->单击Silverlight选项卡(如果还没有)。单击“启用从浏览器中运行的应用程序”旁边的复选框。通过OOB设置按钮(宽度/高度,启用提升信任)修改其任何设置。运行应用程序。这会给你提升权限,让你通过域策略。