2012-08-29 299 views
0

我有一個在我的本地機器完美運行的Silverlight應用程序,從開發服務器(自託管在Windows服務)使用WCF服務。Silverlight跨域問題與WCF自託管在Windows服務

我必須調試其中一個WCF服務,才能找到錯誤的根本原因。我將我的調試/業務跟蹤信息,並安裝在虛擬機(甚至局部),但自那以後,我得到了著名的跨域錯誤:

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

這是奇怪的,因爲如果從開發服務器消耗,它工作正常,但如果在開發機器中安裝服務,甚至在本地(在Windows服務中自行託管),它也不起作用。

這裏是服務原代碼:

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); 
     } 
    } 
} 

在這個問題上閱讀Carlos Figueira's article後,我改變了運用他的方法服務,但仍然沒有工作。

任何想法???

謝謝!

回答

0

嘗試與提琴手,看看你的應用程序真正要求你的服務。

這發生在我身上了幾次,它通常是因爲服務器端口的改變8-)

您ServiceReferences.ClientConfig只需更改服務器端口。

看看你的服務項目配置(網絡選項卡),並設置具體的端口4096,如果你想在那裏把它叫做:

enter image description here

+0

嘿。我已經做了(我應該發佈)。該應用正在請求這兩個文件。針對clientaccesspolicy.xml和crossdomain.xml文件的結果400。我有這兩個,但因爲這是一個自我託管的,我不認爲它能夠得到它。 – Roberto

+0

感謝您的幫助。我確實已將clientconfig更改爲正確的服務器/端口。關於web選項卡,因爲這是一個windows服務,我不認爲我會在服務端有一個。 – Roberto

+0

Ouch,我沒有意識到這不是一個Web項目xD – zapico