I am attempting to connect to an existing WCF service from silverlight (I have tried silverlight 4 and 3 so an answer for either would be great) that starts up via a windows service (though I am just running it from a command line project for the time being) rather than IIS and I am receiving the following error which looks as if it is clientaccesspolicy.xml related:
{System.ServiceModel.CommunicationException: An error occurred while trying to make a request to URI 'http://localhost:8082/SecurityService'. 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. ---> System.Security.SecurityException ---> System.Security.SecurityException: Security error.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
--- End of inner exception stack trace ---
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)
--- End of inner exception stack trace ---
at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult 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 SilverlightApplication1.ServiceReference1.SecurityServiceClient.SecurityServiceClientChannel.EndGetVersionInformation(IAsyncResult result)
at SilverlightApplication1.ServiceReference1.SecurityServiceClient.SilverlightApplication1.ServiceReference1.SecurityService.EndGetVersionInformation(IAsyncResult result)
at SilverlightApplication1.ServiceReference1.SecurityServiceClient.OnEndGetVersionInformation(IAsyncResult result)
at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)}
I have added another service within the services project so i can get the clientaccesspolicy.xml when querying the root of the service and can see in fiddler that this call is successful.
The services are configured as follows:
<behavior name="serviceMetadataBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<serviceThrottling maxConcurrentCalls="30" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
...
<endpointBehaviors>
<behavior name="serviceEndpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
<behavior name="webEndpointBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
...
<service behaviorConfiguration="serviceMetadataBehavior"
name="PolicyService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8082" />
</baseAddresses>
</host>
<endpoint binding="webHttpBinding"
name="PolicyEndpoint"
bindingName=""
contract="IPolicyService"
behaviorConfiguration="webEndpointBehavior" />
</service>
...
<service behaviorConfiguration="serviceMetadataBehavior" name="SecurityService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8082/SecurityService" />
<add baseAddress="net.tcp://localhost:8083/SecurityService" />
</baseAddresses>
</host>
<endpoint binding="basicHttpBinding"
bindingConfiguration="basicHttpBindingConfiguration"
name="SecurityServiceEndpoint"
bindingName=""
contract="ISecurityService"
behaviorConfiguration="serviceEndpointBehavior" />
</service>
and the interfaces for these services are:
[ServiceContract]
public interface IPolicyService
{
[OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")]
Stream GetClientAccessPolicy();
[OperationContract, WebGet(UriTemplate = "/crossdomain.xml")]
Stream GetCrossDomainAccessPolicy();
}
[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.ExceptionShielding("WebService")]
[ServiceContract(Namespace = Namespaces.Services, Name = "SecurityService")]
public interface ISecurityService
{
[OperationContract]
[FaultContract(typeof(GeneralServiceFault))]
Custom.VersionInformation GetVersionInformation(string userName);
}
with the policy service returning the clientaccesspolicy.xml as a stream:
<access-policy>
<cross-domain-access>
<policy>
<allow-from>
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
if I need to give any more information please let me know. Any help much appreciated.