2009-10-16 56 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