1

我正在做一个概念验证,从我的 Silverlight 4 客户端应用程序访问公共 Web 服务。当我尝试调用他的示例公共 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.

我是否只能访问具有这些策略的 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");
4

2 回答 2

2

如果您从您的机器上运行此程序,则很可能您正在跨越域边界并要求被调用站点具有从不同域调用的策略。

Microsoft 有很多关于它的信息,也可以查找“silverlight 跨域”以获取更多信息。

于 2011-03-21T18:37:27.057 回答
1

当服务器收到带有 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>

于 2012-07-05T13:16:03.467 回答