I have made a silverlight application for drag and drop uploading. Now, this application works fine when I deploy it from local server. But whenever I deploy it from QA server (machine on the same LAN but has a global ip associated with it), it does nothing. It just shows a white background screen (default parameter). There is no error that it couldn't find xap file or such, neither any other console errors as well.
I can't seem to figure out what the error is for.
As suggested by some other blogs and posts, I have tried to change the extension from xap to DLL, but still same thing.
Please help.
To access a silverlight app on a remote server, you need to put on the root folder of this server a ClientAccessPolicy.xml file.
A basic one, allowing you to use it from any domain:
<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from>
<Domain uri="*"/>
</allow-from>
<grant-to>
<resource include-subpaths="true" path="/"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
More details here:
http://msdn.microsoft.com/fr-fr/library/cc197955%28v=vs.95%29.aspx
I need to write some data to the DB from a Silverlight 4 application.
I'm using a Silverlight Enabled WCF Web Service. I've published it to IIS7 and added a ClientAccessPolicy.xml file to the inetpub/wwwroot (among other places) so I can access localhost/ClientAccessPolicy.xml just fine. I also added crossdomain.xml just in case.
I also have a Silverlight4 client app which accesses this service and runs through VS2010 on development server.
When trying to invoke a method in the WebService I'm getting a crossdomain error although I have a crossdomain policy in place and the web service is working fine.
When using Fidler I see I'm getting a 304 error when the client app is trying to access the clientaccesspolicy.xml
If I also publish the client app to IIS7 (both under port 80), I can run it using a browser on the same machine with no problem. But when I try to access it on a different machine, I again get a crossdaomain error.
I tried everything but I can't find an answer for this problem anywhere! Please help!!
This is what my ClientAccessPolicy.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="http://*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
I have struggled with this misleading error "crossdomain error" before and after reading your situation I can tell for sure that ClientAccessPolicy.xml configuration is not the issue here you should look elsewhere.
few things i would do
Check my client config & web service configs(double check endpoints, behaviours and finally binding protocols) on the silverlight app.
Enable error logging for your wcf service.
Make sure you are passing the right authentication token to your web service (enable anonymous authentication for the web application hosting WCF service)).
We have a WCF service running on a remote server. It runs as a Windows Service, not hosted in IIS. We can hit this WCF service from our WinForms and WFP apps without any problem. However, when we attempt to hit it from a Silverlight 4 app, we get the following error:
An error occurred while trying to make a request to URI 'http://111.111.111.111/8484/Psn'. 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.
Could someone put this into English and explain what I might be able to do to satisfy Silverlight?
The first thing to check is that you have a clientaccesspolicy.xml file or crossdomain.xml file on the WCF service host. Either of these files can be used to control which domains have access to your service. Without them no one has any access from Silverlight. These files live in the root of the WCF service host:
If, for example, the service is hosted in http://fabrikam.com then the file must be located at http://fabrikam.com/clientaccesspolicy.xml ... [or] ... http://fabrikam.com/crossdomain.xml.
The following clientaccesspolicy.xml file will allow access from http://www.example.com but block it from everywhere else:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="http://www.example.com"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
A similar crossdomain.xml file would be:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="http://www.example.com" headers="SOAPAction,Content-Type"/>
</cross-domain-policy>
Source
I am having a heck of a time calling a RESTful service from within silverlight. I am encountering this error:
{System.Security.SecurityException ---> System.Security.SecurityException: Security error.
at System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
at System.Net.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
--- End of inner exception stack trace ---
at System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
at System.Net.WebClient.OpenReadAsyncCallback(IAsyncResult result)}
Which seems to be a popular error when using the webclient. I have put in place a clientaccesspolicy.xml
<?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>
and I have watched the silverlight in fiddler and it does make a request to the web site and does get a 200 status back.
public void login(string userName, string password)
{
WebClient client = new WebClient();
Uri uri = new Uri(serverURI + "/clientaccesspolicy.xml");
client.OpenReadCompleted += new OpenReadCompletedEventHandler(login_Complete);
client.OpenReadAsync(uri);
}
private void login_Complete(object sender, OpenReadCompletedEventArgs e)
{
byte[] buffer = new byte[e.Result.Length]; //crashes here with exception
...
}
I am more or less out of ideas. Anybody know what I'm doing wrong? Is there some issue with running the silverlight directly from a file:// uri?
Update: I deleted the clientaccesspolicy.xml file and kept just the crossdomain.xml file in place and bingo everything worked. That makes me believe that the error is in the clientaccesspolicy file but I copied that directly from microsoft. What gives?
I just spent 3 hours looking into this very issue. The cross domain access policy and client access policy files were a dead-end for me. Nothing would work. Then finally I ran into a post on the Silverlight.net forums by a Microsoft employee that helped me fix the issue.
The answer, at least in my case was the test webpage that Visual Studio generates when you create a new Silverlight application.
Basically you get two options when you start a Silverlight project. The first option will generate an html page dynamically when you run your application. The second option will create a separate ASP.NET project that will host your Silverlight application. If you choose the first option (dynamic test page) you will not be able to do any cross domain requests, even if both your projects are on the same box it will somehow consider this a cross domain call and fail (I am not sure why)
Create another Silverlight project, choose the second option, and move your XAML files in. That should fix your issue.
You can't request content from a website if your Silverlight application is running from a file:// URL.
For more information, see URL Access Restrictions in Silverlight.
Mmm...
Try with this cross domain file
<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction" >
<domain uri="*"/>
</allow-from>
<grant-to>
<resource include-subpaths="true" path="/"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
X-Cubed is correct, you cannot do cross-domain requests from file://, as Adam Berent pointed out, this means if you use the TestPage generated by visual studio your network requests will fail.
A workaround is to launch the TestPage using Chiron (usually used for dynamic languages) to serve it (because then the access is on http://) or off a development web server.
The catch is you actually have to attach the debugger manually to the browser in order to debug with networking (you can't just hit F5.)
I've seen a lot of links to MSDN and "works on my machine!" answers so I'd like to ask my question with the exact steps to duplicate what I'm doing. Because we are using an already existing webservice, I'm asking with the context of having a webservice hosted outside of my project, unlike many of the tutorials and videos online. So here goes:
*** Create a new ASP.NET webservice project.
It will come with an existing Service.asmx file exposing a "HelloWorld" web method.
View in browser, hit the "Invoke" button. It should work returning the "Hello World" string.
On my machine, the URL is: "http://localhost:15511/WebSite5/Service.asmx"
*** Start a new instance of Visual Studio, create a Silverlight Web Application Project.
*** Stick a single button on there with an event handler to call the web service. I personally nuke the Grid and use a simple StackPanel. eg.
<UserControl x:Class="SilverlightApplication1.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<StackPanel>
<Button Click="Button_Click">
<Button.Content>
<TextBlock Text="Test"/>
</Button.Content>
</Button>
</StackPanel>
</UserControl>
Add the web reference, using statement and event handler for the Button_Click:
private void Button_Click(object sender, RoutedEventArgs e)
{
ServiceSoapClient client = new ServiceSoapClient();
client.HelloWorldCompleted += (object s, HelloWorldCompletedEventArgs ea) => {
MessageBox.Show(ea.Result);
};
client.HelloWorldAsync();
}
Run the Silverlight Application. In my case I'm going to my Silverlight Test Page at:
http://localhost:15558/SilverlightApplication1TestPage.aspx
Run and of course it blows up because of crossdomain issues. So next add the clientaccesspolicy.xml file with the following to the root of your web application hosting the service:
<?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 include-subpaths="true" path="/"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
This should open things up since it's got a wildcard for headers, uris, and resources, right?
Run again and you get an error:
An error occurred while trying to make a request to URI 'http://localhost:15511/WebSite5/Service.asmx'. 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.
So question: is there a secret to the clientaccesspolicy file? One could alternately try with the crossdomain.xml but it gives a similar result.
I've encountered this problem (SL v5.0 and Visual Studio 2010), what fixed it for me is that I went into the Silverlight project properties >> Silverlight tab and selected "Require elevated trust when running in-browser"
I've had this same problem a couple of times. In the past I've solved this by using the Web App as start up, but it looks like you've already done that.
My post on the subject: http://www.donnfelker.com/silverlight-cross-domain-issue/
Make sure that you put the clientaccesspolicy.xml file in the root of IIS web directory e.g.
C:\Inetpub\wwwroot\clientaccesspolicy.xml
This will make sure that it is accessible directly at http:///clientaccesspolicy.xml
I was getting the same error and I resolved it doing the above steps.
Client Configuration
Maybe your ServiceReferences.ClientConfig for your Silverlight client is pointing to the wrong URL?
Also, check the location of your cross-domain policy file. This MSDN article has more information.
Locally Running Silverlight
Additional note for running Silverlight locally (Vista Sidebar, for example). As reported in this blog entry, "Silverlight cannot use any network provider, when running locally." The workaround is to use javascript to interface to the web service in this situation.
Something that worked for me began with what I found on the silverlight forums here. It essentially asked if I could even get to my clientaccesspolicy.xml or crossdomain.xml from localhost (http://localhost/clientaccesspolicy.xml). When I tried to navigate there, I couldn't so I simply found the code for both of them (also within the aforementioned thread), and copy-pasted over the code inside of those files existing in my inetpub\wwwroot\ directory (I opened them up using Notepad++). The weird part was the code didn't change at all , and yet, it works! Hope that helps someone! This was extremely strange.
clientaccesspolicy.xml
<?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>
crossdomain.xml
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
Be blessed!
-sf
Have you tried fiddler when using this through IE, you might be able to see the traffic silverlight is causing, such as which cross policy files it is looking for?
I modified my Internet explorer settings. The website runs on a intern webserver so I added it in the Iexplorer Trusted Sites list. (Tools->Internet Options->Security->Sites).
Then I changed the security level and enabled cross domains. Done, Works but took me while to find the solution.
Best,
Jeppen
You have to be aware of situation that when you reference to your service inside your project there 'll be created file "Reference.ClienConfig" and there is:
**
<endpoint address="http://localhost:57675/Servis.asmx" binding="basicHttpBinding"
bindingConfiguration="ServisSoap" contract="ServiceReference1.ServisSoap"
name="ServisSoap" />
**
Make sure that your page is still using the same port (for example here is 57675). By default your localhost 'll get random port, so you have to change it to be static number and not Dynamic. (Right click on asp.net project/Tab Web/Specific port /type number
Hope it helps
I ran into something like this and adding a ServiceHostFactory fixed my issue. The cross-domain policy file alone did not fix it.
class MyHostFactory : ServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
MyHost customServiceHost =
new MyHost(serviceType, new Uri("[Your URL goes here]",UriKind.Absolute));
return customServiceHost;
}
}
class MyHost : ServiceHost
{
public MyHost(Type serviceType, params Uri[] baseAddresses) base(serviceType, baseAddresses)
{ }
protected override void ApplyConfiguration()
{
base.ApplyConfiguration();
}
}
You also have to add Factory="MyHostFactory" in the tag that defines your service
The problem could be that your development server is not able to serve the xml file, try this - explicitly make it available through WebGet
[ServiceContract]
public interface ICrossDomainService
{
[OperationContract]
[WebGet(UriTemplate = "ClientAccessPolicy.xml")]
Message ProvidePolicyFile();
}
and then the ProvidePolicyFile() can be
public System.ServiceModel.Channels.Message ProvidePolicyFile()
{
FileStream filestream = File.Open(#"ClientAcessPolicy.xml", FileMode.Open);
// Either specify ClientAcessPolicy.xml file path properly
// or put that in \Bin folder of the console application
XmlReader reader = XmlReader.Create(filestream);
System.ServiceModel.Channels.Message result = Message.CreateMessage(MessageVersion.None, "", reader);
return result;
}
It worked in my pc successfully, you can place your
clientaccesspolicy.xml
<?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>
both your project directory and your webservices root.
I was facing the same problem and take more than 3 days to figure out the Problem. I notice also when I was calling the internet Cloud Service WCF from a Silverlight app hosted in another web server it just shows Cross-Domain Errors.
After looking into some posts I didn't solve the problem, even putting cross-domain.xml and clientaccesspolice.xml files in service root directory.
So I just try to instead of using http://example.com I just change it to secure https://example.com and it just worked fine. The cross-domain errors disappears. service was called without problems.
Check which project is set default.
It should be the web project that should be set default and not the silverlight project.