在Silverlight项目中何处放置clientaccesspolicy.xml [英] Where to place clientaccesspolicy.xml in Silverlight project

查看:34
本文介绍了在Silverlight项目中何处放置clientaccesspolicy.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在客户端上有一个Silverlight应用程序,它通过WCF与服务器端进行通信.我偶尔会遇到CommunicationException-特别是在将大量数据传递给服务的某些参数时.有人告诉我,如果我希望Silverlight应用程序与这样的服务器通信,则需要一个clientaccesspolicy.xml文件-防止跨站点脚本编写.

I have a Silverlight application on the client communicating with the server side through WCF. I keep getting a CommunicationException occasionally - and in particular when passing larger amounts of data to some parameters of the service. I have been told that if I want the Silverlight application to communicate with a server like this I need a clientaccesspolicy.xml file - to prevent cross site scripting.

所以-我这样创建了clientaccesspolicy.xml默认值:

So - I created the clientaccesspolicy.xml default like this:

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

但是现在我不知道该放在哪里.我需要告诉任何人它在哪里吗?并且-这可以解决我的问题吗?

But now I don't know where to put it. And do I need to tell anyone where it is? And - might this be the solution to my problems?

推荐答案

是的,当您希望Silverlight与外部资源进行通信时,需要clientclientpolicy.xml.

Yes, you need a clientaccesspolicy.xml when you want Silverlight to communicate with an outside source.

您没有指定WCF服务是作为服务托管,自行托管还是托管在IIS中.如果它在IIS中,则该文件将放置在共享文件夹(网站)的根目录中.

You did not specify whether the WCF service is hosted as a service, self-hosted, or hosted in IIS. If it is in IIS, then the file is placed in the root of the shared folder (website).

如果该服务是自托管的,那么您可以阅读此

If the service is self-hosted, then you can read this article.

对于Windows服务,您可以参考以下文章

For a Windows Service, you can refer to the following article

但是,如果您偶尔仅遇到错误,则可能不是最大的问题.考虑到您说的错误是在尝试发送较大的参数时发生的,这意味着您必须查看WCF服务和客户端的绑定.这些限制通常约为每个呼叫16kb.这可以在服务端通过创建绑定来完成,该绑定将允许传递大量数据.

But if you only get the error occasionally, then it probably is not your biggest issue. Looking at the fact that you say the errors occur when you try to send large parameters around, it means that you will have to look at the bindings of the WCF service, and the client. These limits are normally something like 16kb per call. This can be done on the service side, by creating a binding that will allow for large amounts of data to be passed.

<basicHttpBinding>
        <binding name="NewBinding0" maxBufferSize="104857600" maxReceivedMessageSize="104857600">
          <readerQuotas maxDepth="104857600" maxStringContentLength="104857600"
            maxArrayLength="104857600" maxBytesPerRead="104857600" maxNameTableCharCount="104857600" />
        </binding>
      </basicHttpBinding>

然后将其关联到端点.

如果在客户端上查看ServiceReferences.ClienConfig文件,应该会看到与WCF服务的绑定.

If you look in your ServiceReferences.ClienConfig file on the client side, you should see a binding to a WCF service.

您可以对其进行编辑以使其类似于:

You can edit it to look something like:

<binding name="ProductConfig" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
                  <security mode="None" />
                </binding>

编辑:这是在服务器端添加绑定的方法.

EDIT: Here is how to add the binding on the server side.

  • 右键单击web.config并说编辑WCF配置"
  • 在右侧,有一个树元素绑定"
  • 右键单击并说添加新绑定"
  • 命名绑定并将所有Max *元素设置为任意大的数字.
  • 通过扩展服务并选择您正在使用的端点,将此绑定与端点相关联.在BindingConfiguration中,选择新的绑定.

您还可以通过查找元素将其手动添加到web.config文件中

You can also manually add this to your web.config file, by finding the element

<system.serviceModel>

那里应该有一个< bindings> 子元素.您可以在上面添加绑定,如上所示.然后向下滚动到显示端点的位置,并在其中的xml中添加bindingConfiguration ="NewBinding0"标记.

There should be a <bindings> child element somewhere in there. You can add the binding as shown above in there. And then scroll down to where your endpoints are shown and add a bindingConfiguration="NewBinding0" tag in the xml there.

EDIT练习2 :

好的,当然,这是我的一个项目的外观示例:

Okay, sure, here is an example of what it looks like in one of my projects:

<system.serviceModel>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <extensions>

    </extensions>
    <bindings>
      <basicHttpBinding>
        <binding name="NewBinding0" maxBufferSize="104857600" maxReceivedMessageSize="104857600">
          <readerQuotas maxDepth="104857600" maxStringContentLength="104857600"
            maxArrayLength="104857600" maxBytesPerRead="104857600" maxNameTableCharCount="104857600" />
        </binding>
      </basicHttpBinding>
      <mexHttpBinding>
        <binding name="NewBinding1" />
      </mexHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="policyBehavior">
          <webHttp />
        </behavior>
        <behavior name="NewBehavior" />
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="NewBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="NewBehavior" name="ALMWCFHost.ServiceModel">
        <clear />
        <endpoint address="GuildService" binding="basicHttpBinding" bindingConfiguration="NewBinding0"
          name="ProductConfig" contract="ALMWCFHost.IProductConfigModel"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://omrsrv004/" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>

如果对此有更多问题,请提供有关所使用的IDE的详细信息以及最初如何添加服务端点的信息.

IF you are having more issues with this, please provide details as to what IDE you are using, and how did you add your service endpoints originally.

这篇关于在Silverlight项目中何处放置clientaccesspolicy.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆