Silverlight + WCF commnication exception
I have a silverlight application which has a WCF in it. when the wcf is called it fails with this exception:
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. Pl开发者_JS百科ease see the inner exception for more details.
Both silverlight and WCF are running from local.
My silverlight is running from:
...\SilverlightApplication1\SilverlightApplication1\Bin\Release\SilverlightApplication1TestPage.html
this is the WCF web.config services tag:
<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>
and this is the 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>
I've placed the clientaccesspolicy.xml in bin\release but doesn't help.
HELP PLEASE!
You need some extra configuration to do a cross domain call see:http://www.dotnetcurry.com/ShowArticle.aspx?ID=208&AspxAutoDetectCookieSupport=1
You probably have the clientaccesspolicy.xml in the wrong place, check your IIS log for file not found errors.
The client access policy file must be in your wwwroot folder
There are issues with running Silverlight locally as opposed to from a web server. The access permissions are different and Silverlight won't be able to access ANY webservice. I ran into that issue somne time ago with SL2 I think, it might have changed.
You should create a new WebApplication project in Visual Studio and host Silverlight in it. Then you SL client will have no problem connecting to the service.
精彩评论