2009-10-10 106 views
1

我有一個WCF服務,我已經添加到Silverlight項目,現在託管在Visual Studio的ASP.NET開發服務器。但tyring運行它,我得到以下錯誤:WCF服務和Silverlight 3調試

 
System.ServiceModel.CommunicationException was unhandled by user code 
    Message="An error occurred while trying to make a request to URI 'http://localhost:51547/WCFService1/Service.svc'. 

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." 
    StackTrace: 
     at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result) 
     at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result) 
     at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result) 
     at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result) 
     at niki_lanik_latestnews.WCFXmlOps.IxmlLoadClient.IxmlLoadClientChannel.EndLoadArticleFromXML(IAsyncResult result) 
     at niki_lanik_latestnews.WCFXmlOps.IxmlLoadClient.niki_lanik_latestnews.WCFXmlOps.IxmlLoad.EndLoadArticleFromXML(IAsyncResult result) 
     at niki_lanik_latestnews.WCFXmlOps.IxmlLoadClient.OnEndLoadArticleFromXML(IAsyncResult result) 
     at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result) 
    InnerException: System.Security.SecurityException 
     Message="" 
     StackTrace: 
      at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) 
      at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 
      at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result) 
     InnerException: System.Security.SecurityException 
      Message="Security error." 
      StackTrace: 
       at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) 
       at System.Net.Browser.BrowserHttpWebRequest.c__DisplayClass5.b__4(Object sendState) 
       at System.Net.Browser.AsyncHelper.c__DisplayClass2.b__0(Object sendState) 
      InnerException: 

這不是託管,因爲它是在同一個項目,所以我不知道是什麼原因造成這種跨域?任何想法的人?

託尼

UPDATE

下面是在web.config中我綁定的配置:

 <bindings> 
     <basicHttpBinding> 
      <binding name="basicHTTP" 
      receiveTimeout="00:10:00" 
      sendTimeout="00:10:00" 
      closeTimeout="00:10:00" 
      openTimeout="00:03:00" 
      maxBufferSize="100000" 
      maxReceivedMessageSize="100000" 
      transferMode="StreamedResponse"> 

    </binding> 
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="mexBehavior" name="LoadXMLService.XMLOperations"> 
      <endpoint address="" 
       binding="basicHttpBinding" 
       bindingConfiguration="basicHTTP" 
       contract="LoadXMLService.IxmlLoad" /> 
     </service> 
    </services> 

請記住這個服務應該下載&文件上傳到Silerlight 3項目。

+0

我已將clientaccesspolicy.xml添加到Inetpub的wwwroot。我不確定是否是ASP.NET開發服務器的位置? 當Fiddler2嘗試訪問文件時,出現此錯誤: [Fiddler]連接到本地主機失敗。
異常文本:因目標機器主動拒絕而無法建立連接:: 1:51547 – 2009-10-10 20:52:17

+0

如果使用localhost:51547,那麼我認爲您使用的是Visual Studio內置的Web主機。在你的項目中,你有一個silverlight項目和一個web項目?您可能希望將跨域文件放入您的Web項目中(即與Web.Config處於同一級別)。 – 2009-10-10 21:09:05

+0

我現在把它放在那裏,但它仍然給我同樣的錯誤。我不需要填寫域Uri和Http請求標頭?我不確定,但你能給我一個指導嗎? – 2009-10-10 21:40:01

回答

2

我建議在文件「clientaccesspolicy.xml」中添加以下內容(至少作爲故障排除步驟)到您的網站根目錄。您收到的錯誤似乎表明這將有所幫助。

我的理解是Silverlight認爲交叉端口調用是跨域的(即localhost:51547和localhost:4000是不同的域)。

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

[編輯]

好了,首先要得到它的工作是能夠直接連接到託管服務,所以我會扔出來的問題的一些想法,我跑進。

你有這條線在你的服務?

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
public class MyService 
{ 
} 

和這行在Web.Config中?

<system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"> 
</system.serviceModel>