1

私は、Silverlight4クライアントアプリケーションからパブリック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にはそれに関する情報がたくさんあります。詳細については、「silverlightcrossdomain」も参照してください。

于 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 に答える