Silverlight + WCF通信异常

时间:2011-02-15 10:29:24

标签: silverlight wcf localhost

我有一个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都是从本地运行的。

我的银光正在运行:

...\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中,但没有帮助。

请帮忙!

3 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

客户端访问策略文件必须位于wwwroot文件夹

答案 2 :(得分:0)

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

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