2009-10-10 108 views
1

我有一个WCF服务,我已经添加到Silverlight项目,现在托管在Visual Studio的ASP.NET开发服务器。但tyring运行它,我得到以下错误:WCF服务和Silverlight 3调试

 
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: 

这不是托管,因为它是在同一个项目,所以我不知道是什么原因造成这种跨域?任何想法的人?

托尼

UPDATE

下面是在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> 

请记住这个服务应该下载&文件上传到Silerlight 3项目。

+0

我已将clientaccesspolicy.xml添加到Inetpub的wwwroot。我不确定是否是ASP.NET开发服务器的位置? 当Fiddler2尝试访问文件时,出现此错误: [Fiddler]连接到本地主机失败。
异常文本:因目标机器主动拒绝而无法建立连接:: 1:51547 – 2009-10-10 20:52:17

+0

如果使用localhost:51547,那么我认为您使用的是Visual Studio内置的Web主机。在你的项目中,你有一个silverlight项目和一个web项目?您可能希望将跨域文件放入您的Web项目中(即与Web.Config处于同一级别)。 – 2009-10-10 21:09:05

+0

我现在把它放在那里,但它仍然给我同样的错误。我不需要填写域Uri和Http请求标头?我不确定,但你能给我一个指导吗? – 2009-10-10 21:40:01

回答

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>