2011-02-15 98 views
0

我有一個Silverlight應用程序,它有一個WCF。當wcf被調用時失敗,出現以下異常:Silverlight + 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中,但沒有幫助。

幫助請!

回答

0

你需要一些額外的配置做一個跨域呼叫請參閱:HTTP://www.dotnetcurry.com/ShowArticle.aspx ID = 208 & AspxAutoDetectCookieSupport = 1

你可能有在clientaccesspolicy.xml?錯誤的地方,檢查你的IIS日誌找不到文件錯誤。

+0

我的電腦上沒有IIS – gln 2011-02-15 10:45:20

0

客戶端訪問策略文件必須在你的wwwroot文件夾

+0

如果我沒有IIS,wwwroot文件夾是什麼? – gln 2011-02-15 11:59:02

0

有與本地運行的Silverlight從Web服務器而不是問題。 訪問權限不同,Silverlight將無法訪問任何Web服務。我以前遇到過SL2的問題,我想它可能已經改變了。

您應該在Visual Studio中創建一個新的WebApplication項目並在其中託管Silverlight。 然後你SL客戶端連接到服務將沒有問題。