从 Silverlight 4 客户端访问 SOAP Web 服务

发布于 2024-10-25 02:49:43 字数 1465 浏览 2 评论 0原文

我正在进行概念验证,从 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");

I am doing a proof of concept where I access a public web service from my Silverlight 4 client application. When I attempt to make the call this sample public web service, I get the following error:

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.

Can I only access web services which have these policies in place or am I simply not configuring my ASMX service correctly in my project? The code to call the service is as follows:

   // 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");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酷炫老祖宗 2024-11-01 02:49:43

如果您从计算机上运行此程序,则很可能会跨越域边界,并要求被调用站点制定从不同域进行调用的策略。

Microsoft 有大量相关信息,查找“silverlight跨域”以获取更多信息。

Most likely if you're running this from your machine, you're crossing domain boundaries and require the called site to have the policies in place to call from a different domain.

Microsoft has plenty of information about it, also look up 'silverlight cross domain' for more information.

情栀口红 2024-11-01 02:49:43

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

when server received the GET with url= /clientaccesspolicy.xml
make sure it answers with:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文