代码之家  ›  专栏  ›  技术社区  ›  Steve

WCF/CSLA地狱

  •  1
  • Steve  · 技术社区  · 17 年前

    我正在尝试构建一个概念验证CSLA 3.7/Silverlight 3应用程序,并一直在努力通过 Rocky's tutorials . 这是一个非常简单的单窗体/单业务对象数据编辑应用程序,在我尝试配置WCF以便Silverlight应用程序可以与数据门户进行对话之前,一切都非常完美。

    我得到的错误是:

    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.
    

    我完全被这个迷惑了,因为我对Silverlight和WCF来说有点像N00B。对于CSLA Silverlight应用程序,我的设置非常直接。我有4个项目:

    • cslasilverlight:Silverlight项目
    • cslasilverlight.client:Silverlight类库
    • cslasilverlight.server:.net类库
    • cslasilverlight.web:aspnet项目以承载SL应用程序

    所有的东西都在卡西尼的笔记本电脑上运行。我希望DataPortal在Silverlight之外运行,以便访问SQL Server。我认为问题可能出在Silverlight应用程序中的wcf配置上,该应用程序在servicereferences.clientconfig文件中指定:

    <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>
    
    1 回复  |  直到 17 年前
        1
  •  3
  •   Andrew    17 年前

    如果我认为它是正确的,那么错误可能是告诉您完全正确的事情,您缺少跨域策略。Silverlight应用程序正在从远程位置访问WCF服务,需要授权才能接受请求。

    当这个项目分为三个部分时,我在dev中遇到了这个问题:SL应用程序、WCF Web服务和网站。网站和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>
    

    该文件是一个允许任何人和任何事情,您可以为生产优化它,但在dev中,这是最简单的方法。google wcf客户端访问策略/wcf跨域策略-这是一个常见问题。

    推荐文章