【问题标题】:Silverlight + WCF commnication exceptionSilverlight + WCF 通信异常
【发布时间】:2011-06-27 12:19:33
【问题描述】:

我有一个 Silverlight 应用程序,其中有一个 WCF。当调用 wcf 时,它会失败并出现以下异常:

An error occurred while trying to make a request to URI 'http://localhost:4693/MapService.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 都是从本地运行的。

我的 silverlight 从以下位置运行:

...\SilverlightApplication1\SilverlightApplication1\Bin\Release\SilverlightApplication1TestPage.html

这是 WCF web.config 服务标签:

<services>
        <service behaviorConfiguration="FileUpAndDownload.Web.MapServiceBehavior" name="FileUpAndDownload.Web.MapService">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MapBinding" contract="FileUpAndDownload.Web.IMapService">
                <identity>
                    <dns value="localhost"/>
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>

这是 ServiceReference.ClientConfig:

<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IMapService" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:4693/MapService.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IMapService" contract="MapService.IMapService"
            name="BasicHttpBinding_IMapService" />
    </client>
</system.serviceModel>

我已将 clientaccesspolicy.xml 放在 bin\release 中,但没有帮助。

请帮忙!

【问题讨论】:

    标签: silverlight wcf localhost


    【解决方案1】:

    您需要一些额外的配置才能进行跨域调用,请参阅:http://www.dotnetcurry.com/ShowArticle.aspx?ID=208&AspxAutoDetectCookieSupport=1

    您可能将 clientaccesspolicy.xml 放在错误的位置,请检查您的 IIS 日志中的文件未找到错误。

    【讨论】:

      【解决方案2】:

      客户端访问策略文件必须在您的 wwwroot 文件夹中

      【讨论】:

      • 如果我没有 IIS,那么 wwwroot 文件夹是什么?
      • 您需要确保您可以访问具有相同 uri 前缀的 ClientConfig 文件。例如:localhost:4693/clientaccesspolicy.xml。例如,如果您使用开发服务器,则右键单击其属性并找到物理路径。还要确保当您使用 ClientAccessPolicy 文件时,正确定义了您的端口号。出于测试目的,我总是使用跨域文件。
      【解决方案3】:

      在本地而不是从 Web 服务器运行 Silverlight 存在问题。 访问权限不同,Silverlight 将无法访问任何 Web 服务。 我之前在 SL2 中遇到过这个问题,我想它可能已经改变了。

      您应该在 Visual Studio 中创建一个新的 WebApplication 项目并在其中托管 Silverlight。 那么你的 SL 客户端连接到服务就没有问题了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多