简体   繁体   English

Silverlight跨域问题与WCF自托管在Windows服务中

[英]Silverlight Cross-domain issue with WCF self-hosted in windows service

I have a Silverlight application that is running perfectly in my local machine, consuming WCF services form a development server (self-hosted in windows services). 我有一个Silverlight应用程序,该应用程序在本地计算机上运行完美,使用了开发服务器(在Windows服务中自行托管)中的WCF服务。

I have to debug one of the WCF services, in order to find the root cause of a bug. 为了找到错误的根本原因,我必须调试WCF服务之一。 I added my debug/tracing info in the service, and installed in a virtual machine (and even locally), but since then, I get the well-known cross-domain error: 我在服务中添加了调试/跟踪信息,并安装在虚拟机(甚至本地)中,但是从那时起,我得到了众所周知的跨域错误:

"An error occurred while trying to make a request to URI 'http://MyVMMachine:4096/MyService'. 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." “发生错误,而试图做出URI请求的‘http:// MyVMMachine:4096 /则将MyService’,这可能是由于在尝试跨域方式访问服务没有正确的跨域策略到位,或者说是不适合SOAP服务的政策,你可能需要联系服务的业主发布跨域策略文件,并确保它允许SOAP有关的HTTP标头进行发送。这个错误也可以通过使用引起的Web服务代理中使用内部类型而不使用InternalsVisibleToAttribute属性。请参阅内部异常以获取更多详细信息。”

That's strange, because if consuming from a dev server, it works fine, but if installing the service in a dev machine, or even locally (self-hosted in windows service as well), it doesn't work. 这很奇怪,因为如果从开发服务器进行消费,则可以正常工作,但是如果将服务安装在开发机中,甚至在本地安装(也可以在Windows服务中自行托管),则无法正常工作。

Here is the service original code: 这是服务的原始代码:

public partial class WindowsService : ServiceBase
{
    ServiceHost _Host;

    public WindowsService()
    {
        try
        {
            InitializeComponent();
        }
        catch (Exception exc)
        {
            Server.One.Log("Windows service initialization failed: " + exc.Message);
        }
    }

    protected override void OnStart(string[] args)
    {
        try
        {
            Server.One.Start();
            _Host = new ServiceHost(typeof(Service));
            _Host.Open();
        }
        catch (Exception exc)
        {
            Server.One.Log("Windows service start failed: " + exc.Message);
        }
    }

    protected override void OnStop()
    {
        try
        {
            if (_Host != null)
                _Host.Close();
            Server.One.Stop();
        }
        catch (Exception exc)
        {
            Server.One.Log("Windows service stop failed: " + exc.Message);
        }
    }
}

After reading Carlos Figueira's article on this subject, I changed the service applying his approach, but still not working. 在阅读卡洛斯·菲格伊拉(Carlos Figueira)关于该主题的文章后 ,我使用他的方法更改了服务,但仍然无法正常工作。

Any ideas??? 有任何想法吗???

Thanks! 谢谢!

Try with fiddler to see where is your application really asking for your service. 尝试与提琴手一起看看您的应用程序真正在哪里请求您的服务。

This has happened to me a couple of times and it usually was because of server port changes 8-) 这发生在我身上几次,通常是因为服务器端口更改8-)

Just change your ServiceReferences.ClientConfig to the server port. 只需将ServiceReferences.ClientConfig更改为服务器端口即可。

Take a look at your Service project configuration (web tab) and set the specific port as 4096 if you want to call it there: 查看您的Service项目配置(Web选项卡),如果要在此调用特定端口,则将其设置为4096:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM