2009-10-16 60 views
1

我試圖建立一個概念證明Csla 3.7/Silverlight 3應用程序,並已通過我的方式通過Rocky's tutorials。這是一個非常簡單的一種形式/一個業務對象數據編輯應用程序,並且一切都很好,直到我嘗試配置Wcf以便Silverlight應用程序可以與數據門戶進行通信。WCF/Csla地獄

我得到的錯誤是:

CommunicationException was unhandled by user code 

An error occurred while trying to make a request to URI 'http://localhost:1406/WcfPortal.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. 

我完全被這個迷惑,因爲我是一個有點的n00b的Silverlight的& WCF。我的設置對於Csla Silverlight應用程序來說非常簡單。我有4個項目:

  • CslaSilverlight:Silverlight項目
  • CslaSilverlight.Client:Silverlight的類庫
  • CslaSilverlight.Server:.NET類庫
  • CslaSilverlight.Web:ASPNET項目主辦SL應用

所有東西都在我的筆記本電腦上在卡西尼本地運行。我想讓DataPortal在Silverlight之外運行,以便可以訪問SQL Server。我認爲這個問題可能與我的WCF配置,其中在ServiceReferences.ClientConfig文件中指定的Silverlight應用程序:

<configuration> 
    <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="BasicHttpBinding_IWcfPortal" maxBufferSize="65536" 
        maxReceivedMessageSize="65536" receiveTimeout="10" sendTimeout="10"> 
       </binding> 
      </basicHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://localhost:1406/WcfPortal.svc" 
       binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWcfPortal" 
       contract="Csla.WcfPortal.IWcfPortal" name="BasicHttpBinding_IWcfPortal" /> 
     </client> 
    </system.serviceModel> 
</configuration> 

我想知道如果端口號重要的是,當我改變它,我得到一個不同的錯誤。我也想知道端點地址的格式是否正確。

不知道它是很重要的,但是從ASPNET的web.config我serviceModel設置:

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WcfPortalBehavior"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service behaviorConfiguration="WcfPortalBehavior" name="Csla.Server.Hosts.Silverlight.WcfPortal"> 
     <endpoint address="" binding="basicHttpBinding" contract="Csla.Server.Hosts.Silverlight.IWcfPortal"> 
      <identity> 
      <dns value="localhost"/> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 
    </system.serviceModel> 

回答

3

如果我想是正確的,那麼誤差可能會告訴你完全正確的事情,你是缺少跨域策略。 Silverlight應用程序正在從遠程位置訪問WCF服務,並需要授權才能接受請求。

當項目分爲三部分,SL App,WCF Web服務和網站時,在dev中發生這種情況。網站和WCF服務是獨立運行的,儘管它們是同一解決方案的一部分。因爲這樣的卡西尼跑了兩次,你正在穿越一個邊界。

我有一個clientaccesspolicy.xml文件與開發Web服務,它具有以下沿着:​​

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

該文件是一個允許任何人,一切,你會完善它的生產,但在開發它是最簡單的方法。 Google wcf客戶端訪問策略/ wcf跨域策略 - 這是一個常見問題。

+0

聽起來合乎邏輯。我按照你的建議google了,並且我已經在根文件夾中的ASPNET web應用程序中添加了一個clientaccesspolicy.xml文件,但它沒有任何作用! – Steve

+0

我有我的直接在Web服務的.svc文件相同的位置。你有沒有找到它? – Andrew

+0

doh!它的工作,只是一次...突然我現在得到 「遠程服務器返回一個錯誤:NotFound」 卡西尼已啓動並在端口3405上運行。我的端點地址是http:// localhost:3405/WcfPortal.svc – Steve