WCF服务和Silverlight 3调试

时间:2009-10-10 16:39:31

标签: wcf silverlight

我有一个WCF服务,我已经添加到Silverlight项目中,现在托管在Visual Studio的ASP.NET Dev Server中。但是要运行它我会收到以下错误:

System.ServiceModel.CommunicationException was unhandled by user code
  Message="An error occurred while trying to make a request to URI 'http://localhost:51547/WCFService1/Service.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."
  StackTrace:
       at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
       at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
       at niki_lanik_latestnews.WCFXmlOps.IxmlLoadClient.IxmlLoadClientChannel.EndLoadArticleFromXML(IAsyncResult result)
       at niki_lanik_latestnews.WCFXmlOps.IxmlLoadClient.niki_lanik_latestnews.WCFXmlOps.IxmlLoad.EndLoadArticleFromXML(IAsyncResult result)
       at niki_lanik_latestnews.WCFXmlOps.IxmlLoadClient.OnEndLoadArticleFromXML(IAsyncResult result)
       at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)
  InnerException: System.Security.SecurityException
       Message=""
       StackTrace:
            at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
            at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
            at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
       InnerException: System.Security.SecurityException
            Message="Security error."
            StackTrace:
                 at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
                 at System.Net.Browser.BrowserHttpWebRequest.c__DisplayClass5.b__4(Object sendState)
                 at System.Net.Browser.AsyncHelper.c__DisplayClass2.b__0(Object sendState)
            InnerException: 

它不是托管跨域,因为它在同一个项目中,所以我不确定是什么原因引起的?任何人的想法?

更新

以下是我在web.config中的绑定配置:

        <bindings>
        <basicHttpBinding>
            <binding name="basicHTTP" 
             receiveTimeout="00:10:00" 
             sendTimeout="00:10:00" 
             closeTimeout="00:10:00" 
             openTimeout="00:03:00" 
             maxBufferSize="100000" 
             maxReceivedMessageSize="100000" 
             transferMode="StreamedResponse">

    </binding>
        </basicHttpBinding>
    </bindings>
    <services>
        <service behaviorConfiguration="mexBehavior" name="LoadXMLService.XMLOperations">
            <endpoint address="" 
              binding="basicHttpBinding" 
              bindingConfiguration="basicHTTP" 
              contract="LoadXMLService.IxmlLoad" />
        </service>
    </services>

请记住此服务应该是download&amp;将文件上传到Silerlight 3项目。

1 个答案:

答案 0 :(得分:2)

我建议将文件“clientaccesspolicy.xml”添加到您的网站根目录中,其中包含以下内容(至少作为故障排除步骤)。您收到的错误似乎表明这会有所帮助。

据我了解,Silverlight认为跨端口调用是跨域的(即localhost:51547和localhost:4000是不同的域)。

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

<强> [编辑]

嗯,让它工作的第一件事就是能够直接连接到托管服务,所以我会抛出一些我遇到的问题的想法。

你的服务中有这条线吗?

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService
{
}

和Web.Config中的这一行?

<system.serviceModel>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
</system.serviceModel>