1

192.168.0.199:87 で実行されている WCF サービスを作成しました。サービスは問題なく動作します。ただし、VS の開発用 PC でこのサービスを使用する Silverlight アプリを作成すると、クロスドメインの問題が発生します。どうすればこれを解決できますか? サービスは IIS WCF サービスではありません。また、WCF サービスと Silverlight アプリを同じポートでホストすることもできません。Silverlight は 192.178.0.199:87 で clientaccesspolicy.xml を探しています。この場合、これは自分でホストする WCF サービスのアドレスです。

どんな助けでも素晴らしいでしょう。

これは、何か良いものを醸造できるかどうかわからない私のコードです。私の app.config ファイルはここにあります。エンドポイントの問題だと思いますが、よくわかりません。 http://213.46.36.140/app.config.txt

namespace WindowsFormsApplication11
{
    public partial class Form1 : Form
    {
        public ServiceHost _host = null;

        public Form1()
        {
            InitializeComponent();
        }      

        private void button1_Click(object sender, EventArgs e)
        {
            _host = new ServiceHost(typeof(WmsStatService));
            _host.Open();
        }
    }

    // Define a service contract.
    [ServiceContract(Namespace = "http://WindowsFormsApplication11")]
    public interface IWmsStat
    {
        [OperationContract]
        string sayHello(string name);
        [OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")]
        Stream GetSilverlightPolicy();
    }

    public class WmsStatService : IWmsStat
    {
        public string sayHello(string name)
        {
            return "hello there " + name + " nice to meet you!";
        }

        Stream StringToStream(string result)
        {
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
            return new MemoryStream(Encoding.UTF8.GetBytes(result));
        }
        public Stream GetSilverlightPolicy()
        {
            // result cointains the clienaccpolicy.xml content.
            //
string result = @"<?xml version=""1.0"" encoding=""utf-8""?>
<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>
</access-policy>";
            return StringToStream(result);
        }
    }
}
4

0 に答える 0