WCF / Csla 地狱

发布于 2024-08-07 18:33:15 字数 3197 浏览 2 评论 0原文

我正在尝试构建一个概念验证 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 和 Silverlight 有点不熟悉。世界CF。对于 Csla Silverlight 应用程序,我的设置非常简单。我有 4 个项目:

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

一切都在我的笔记本电脑上的 Cassini 下本地运行。我希望 DataPortal 在 Silverlight 之外运行,以便我可以访问 SQL Server。我认为问题可能出在 ServiceReferences.ClientConfig 文件中指定的 Silverlight 应用程序中的 Wcf 配置:

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

I'm trying to build a proof of concept Csla 3.7/Silverlight 3 app and have been working my way through Rocky's tutorials. It's a really simple one form/one business object data editing app and everything is just peachy right up until the point where I try to get the Wcf configured so that the Silverlight app can talk to the Data Portal.

The error I'm getting is:

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.

I'm totally mystified by this as I'm a bit of a n00b to Silverlight & WCF. My setup is pretty straight forward for a Csla Silverlight app. I have 4 projects:

  • CslaSilverlight : Silverlight Project
  • CslaSilverlight.Client : Silverlight Class Library
  • CslaSilverlight.Server : .NET Class Library
  • CslaSilverlight.Web : ASPNET Project to host the SL app

Everything is running locally on my laptop under Cassini. I want the DataPortal to run outside of Silverlight so that I can access SQL Server. I think that the problem may be with my Wcf Config in the Silverlight application which is specified in a ServiceReferences.ClientConfig file:

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

I'm wondering if the port number important, when I change it I get a different error. I'm also wondering if the format of the endpoint address correct.

Not sure if it's important, but my serviceModel settings from the ASPNet web.config are:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守不住的情 2024-08-14 18:33:15

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

我在开发阶段就遇到过这种情况,当时项目分为三个部分: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>

该文件允许任何人和所有事物,您可以对其进行改进以用于生产,但在开发中这是最简单的方法。 Google wcf 客户端访问策略/wcf 跨域策略 - 这是一个常见问题。

If I am thinking it right, then the error may be telling you the entirely correct thing, you are missing a cross domain policy. The silverlight app is accessing the WCF service from a remote location and needs the authorisation to accept the request.

This occured for me in dev when the project was in three parts, the SL App, the WCF web service and the website. The web site and WCF service are run independantly, although they were a part of the same solution. As such Cassini is run twice and you are crossing a boundary.

I have a clientaccesspolicy.xml file along with the web service in development that has the following:

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

The file is a allowing anyone and everything, you would refine it for production, but in dev it was the easiest way. Google wcf client access policy / wcf cross domain policy - it is a common issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文