1

我正在尝试构建一个概念验证 Csla 3.7/Silverlight 3 应用程序,并且一直在学习Rocky 的教程。这是一个非常简单的单表单/单业务对象数据编辑应用程序,直到我尝试配置 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 有点不了解。对于 Csla Silverlight 应用程序,我的设置非常简单。我有4个项目:

  • CslaSilverlight : Silverlight 项目
  • CslaSilverlight.Client:Silverlight 类库
  • CslaSilverlight.Server:.NET 类库
  • CslaSilverlight.Web:托管 SL 应用程序的 ASPNET 项目

一切都在我的笔记本电脑上在 Cassini 下本地运行。我希望 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>
4

1 回答 1

3

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

当项目分为三个部分(SL 应用程序、WCF Web 服务和网站)时,我在 dev 中发生了这种情况。网站和 WCF 服务是独立运行的,尽管它们是同一解决方案的一部分。因此,Cassini 运行了两次,您正在跨越边界。

我有一个 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 跨域策略 - 这是一个常见问题。

于 2009-10-16T08:55:43.813 回答