I understand this question has been answered many times but i could not resolve it for some reason. I hope some one can solve my problem which might be straightforward for many, but i some how couldnt figure it out as I am relatively new to silverlight and web. I have tried all the possible samples available in the internet on cross domain errors but couldnt fix it. I appreciate if any once can help me on this issue i am facing.
I am accessing WCF service from Silverlight 4 client. I have Clientacccesspolicy.xml and Crossdomain.xml in the wwwroot.
I can access my file by using [http://localhost/Remoteapp.html]. But i am getting cross domain error inspite of having the Clientaccesspolicy.xml file in the root, when the application tries to make a webservice call.
In the webdevelopementhelper i can see that the clientaccesspolicy is being requested at the wcfservice port which is [http//localhost:600061/clientaccesspolicy.xml], which is where my service is located and i am getting a 502 response[Connection failed].
When I type [http://localhost/Clientaccesspolicy.xml] in the browser i can locate the file. But silverlight is requesting the policy file at a wrong location.
Every thing works properly in the design time, but when i deploy it to IIS i am getting this error.
Can any one help me how to resolve this issue? Thanks to every one in advance.
Step 1:
check that you have a clientaccesspolicy.xml file or crossdomain.xml file on the WCF service host.
The following clientaccesspolicy.xml
<?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 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="*" headers="*"/>
</cross-domain-policy>
if that does not work, try these steps
On the server where the silver light application is deployed , typically in the ClientBin folder of the ASP.NET application, rename the silverlight application file *.xap to *.zip
Extract the contents of the zip file
Edit the ServiceReferences.ClientConfig file
Update the end point address from localhost to the server address where the WCF service is hosted.
Save the file. Zip the contents and rename back to .xap
Step 1: Put crossdomain.xml with the following code into your web service hosting folder.
<?xml version="1.0" ?>
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
Step 2: Put the same file in your silverlight project also when you add reference of above WCF webservice.
Step 3: Update your reference and publish silverlight project.
Try these steps. It will work for sure.
I have also faced the same issue and after a week of my trails got to know that having ClientAcessPolicy.xml and CrossDomainPolicy.xml in the root directory will not serve u r request, the ClientAcessPolicy.xml and CrossDomianPolicy.xml must be sent through the service only.
Follow the below steps to solve this issue
Add a new NameSpace in Iservice1.cs as shown below
[ServiceContract(Namespace = "http://ServiceWCF")]
public interface IPolicyRetriever
{
[OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")]
Stream GetSilverlightPolicy();
[OperationContract, WebGet(UriTemplate = "/crossdomain.xml")]
Stream GetFlashPolicy();
};
Now edit the Service1.svc file with edits,
public class PolicyClass : IPolicyRetriever
{
Stream StringToStream(string result)
{
WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
return new MemoryStream(Encoding.UTF8.GetBytes(result));
}
public Stream GetSilverlightPolicy()
{
string result = #"<?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>";
return StringToStream(result);
}
public Stream GetFlashPolicy()
{
string result = #"<?xml version=""1.0""?>
<!DOCTYPE cross-domain-policySYSTEM""http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"">
<cross-domain-policy>
<allow-access-from domain=""*"" />
</cross-domain-policy>";
return StringToStream(result);
}
}
Now Add both the file in the Project Location
Better to avoid some of the problems we can add both the file in the Root Folder also
These are some of the changes that have to be made in the Internet Explorer also, after the service is up and running now test in the browser whether the ClientAccesspolicy.xml and Crossdoaminpolicy.xml is accessible from Internet explorer. After all this is done the Microsoft Azure VM link must be added as a trusted site or domain in the browser
First navigate to Internet Explorer-> Internet Options ->Security ->Local Intranet-> Sites
Now check the Check box for Automatically detect intranet network click on Advanced and add the respective Site URL of the VM
Internet Explorer-> Internet Options ->Security ->Trusted Site, add the SP2013 URL which as an added URL
Now in the same window click on the Custom Level Enable all .Net Framework, Active X Controls, Enable .Net Framework Setup
Now move to the advanced Tab and uncheck the Disable the Script Debugging(Internet Explorer), Disable the Script Debugging(others)
In the same Tab we also need to enable some of the options and they are Allow Active Contents from CD's to run on my computer, Allow Active Controls to run in files on my Computer, Enable Native XMLHTTP Support.
After all these are done check weather the Sliverlight application is running properly. For sure if these steps are handles correctly the application will run perfectly.
Related
There are two modules one is silverlight application(like a client) and another one is wcf service which is self hosted service . Here both the application works like client and server communication. Those two applications are communicating properly in windows 7 and previous versions but not in win 8.
There is an error like "
An error occurred while trying to make a request to URI "localhost:8283/MyTestService". 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."
I tried a many ways which i referred from internet but not able to create connection between them in windows 8.
I tried these ways :
1).added two files clientaccesspolicy.xml and crossdomain.xml to the IIS8(wwwroot) folder as referred by MSN..
2).Giver all permissions to respective folders.
what may be the possible solutions for this ?
1). any security issues might be there
2). windows 8 is enterprise edition
If any more details required let me know in comments.
I am looking forward for your respond..
After so much of R&D , i got the solution to work silverlight and WCF service in windows 8 environment. I am answering to my question if it may helpful to anybody caught in this type of error ..
Actual Cause :
No communication is creating in between CVT Service(WCF service) and CVT pages(silver light application) as client side. Whenever it compiled in windows 8 environment . Then the error caught was “ An error occurred while trying to make a request to URI ‘http://localhost:8283. 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. Please see the inner exception for more details. “.
Resolution :
The actual problem is present in WCF service . Below steps to be followed to run the WCF service successfully and make it communicate properly with silver light application in windows 8 environment. In windows 7 and previous versions the settings related to WCF service work will be enabled by default but in win 8 few features might not be enabled in that case you can follow these below steps.
step 1 :
create and add two XML files to wwwroot folder. This folder is located in this path “C:\inetpub\wwwroot”.
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>
</xml>
b). 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="SOAPAction,Content-Type"/>
</cross-domain-policy>
Step 2 : If this feature is not activated , enable this feature by following the below steps.
Hit Windows+x.
Select Programs and Features(first item on list).
Select Turn Windows Features on or off on the left.
Expand .Net Framework 4.5 Advanced Services.
Expand WCF services.
Enable HTTP Activation.
Step 3 : Adding MIME Type and new managed handler
WCF services don’t run on IIS 8 with the default configuration, because the web server doesn’t know, how to handle incoming requests targeting .svc files. You can teach it in two steps:
Refer below link :
https://gyorgybalassy.wordpress.com/2012/09/24/
Step 4 : Application should be compiled in windows 8 environment .
We need to follow these steps to run this application in windows 8 environment.
Good day to all,
We've encountered some configuration problem while retrieving an end point from configuration file at creating a ChannelFactory object.
Could not find endpoint element with name 'no matter service'
and contract 'no matter contract' in the ServiceModel client configuration section. This might be
because no configuration file was found for your application, or
because no endpoint element matching this name could be found in the
client element.
The usual solution at this kind of exception is to add .config file to exe that runs this code.
In this case we're running this code at com+ so i'd created dllhost.exe.config file with all the endpoints.
The intresting thing is that i'm using this service also from a client application and there my wcf platform founds the same endpoint without any problem.
Other endpoints at dllhost.exe.config working fine i think.
By the way the problematic proxy that uses this service is customised Enterprise Library code.
While debugging the code it is defenetly runs under the dllhost process.
Is there some way to find out it what config file it looks for the endpoint?
Thank you.
Well, after a few days of checking and testing we'd found out 2 ways to solve the problem:
dllhost.exe.config - should not be edited/created/updated manually,but from MSI.Probably the reason is that is is placed at system32 directory and windows blocks it.
Better way - is to create for COM+ Service Application Root Directory and place there 2 files
ServiceName.config - Contains list of endpoints
ServiceName.manifest - Contains 3 rows
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
</assembly>
(I see several questions related to my problem but none of the solutions work for me as I am encountering this problem in production, not during local development, and I've already tried all of the proposed fixes.)
I have a Silverlight 4 application that uses WCF services hosted by IIS. In production these services are accessed over HTTPS. Despite having a valid crossdomain.xml file I still get the famous "Security error" when accessing the service:
An error occurred while trying to make a request to URI
'https://MYDOMAIN/MYSERVICE.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. --->
System.Security.SecurityException --->
System.Security.SecurityException: Security error...
Using Fiddler I can see that no request is made to crossdomain.xml or clientaccesspolicy.xml. There is a CONNECT request to the server but that is all.
I've read that this error, though it indicates a problem with crossdomain.xml/clientaccesspolicy.xml, can also be raised when the server issues an invalid certificate. This does not seem to be the case in my scenario.
I am certain the following is set up correctly:
1. crossdomain.xml is valid and hosted in the root of the site
2. The services do work (We have other clients in various technologies that use them, including Adobe Flex which relies on crossdomain.xml.)
3. The Silverlight app does work (It works just fine with local services and services on a shared development server***)
4. The Silverlight app does not even try to request crossdomain.xml or clientaccesspolicy.xml (as confirmed by Fiddler)
5. The Silverlight app uses the proper config for accessing WCF over https. Below is the configuration:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyServices" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://MYDOMAIN/MYSERVICE.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyServices" contract="Services.IMyServices" name="BasicHttpBinding_IMyServices" />
</client>
</system.serviceModel>
</configuration>
What else can cause this kind of problem? Could it be because the web servers are load balanced? Or is there a problem with the certificate that I haven't noticed? If you can at least point me in the right direction that would be much appreciated.
(***Something worth pointing out: I came upon a similar problem in our development environment. The Silverlight app was unable to access WCF services on a shared development server, despite having a proper crossdomain.xml and not using HTTPS. I worked around it by adding the development server as a trusted site in IE. However this same workaround does not work for production, and even then it wouldn't be an acceptable workaround. But the fact that I had to do this in the development environment makes me worried that I've missed something along the way...)
The problem was that I was missing clientaccesspolicy.xml. Having crossdomain.xml was not sufficient in this case. I think this is because the WCF invocation was not just cross-browser but also cross-protocol (the Silverlight app was served via http but the services were served via https).
In addition, my clientaccesspolicy.xml had to explicitly allow access for http as follows:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<!-- IMPORTANT! Include these lines -->
<domain uri="http://*"/>
<domain uri="https://*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
It now works like a charm.
A couple of things that tripped me up along the way:
My browser was caching clientaccesspolicy.xml and crossdomain.xml. I would have to clear my cache every time I changed one of those files or it wouldn't recognize the newer version, despite the fact that IIS is configured to prevent client caching of this file.
The requests to clientaccesspolicy.xml and crossdomain.xml were not always showing up in Fiddler. I would often see CONNECT requests instead. I don't understand the reason for this but I've learned not to rely on Fiddler to confirm these requests are being made. Perhaps I have some rogue setting somewhere (it's not the "Decrypt HTTPS traffic" setting because I already disabled it).
I have the same error, when I try to make a call to my site over http and my service was over https it failed. This error occured because my ISS had no certificate, so, when the app tried to download the clientaccesspolicy, it failed.
Take a look in any debug tool on your browser and look for clientacccesspolicy file, then check that if it is being downloaded.
I am developing a custom HttpHandler, to do so I write a C# Class Library and compile to DLL.
As part of this I have some directory locations which I want not hard coded in the app, so i'm trying to put it in the app.config which I've used before.
Before this has worked by just going building the app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Share" value="C:\...\"/>
</appSettings>
</configuration>
And then obtaining this in code like:
var shareDirectory = ConfigurationManager.AppSettings["Share"];
But when I compile it and put it in the bin folder for the webservice, it keeps getting null for shareDirectory, probably because it can't find app.config. So how do I make sure this is included so I don't have to hard code my direcotry locations? I notice it will essentially after compiled we get the assembly.dll and the assembly.dll.config which is the app.config file, so it's definetly there in the bin folder!
That is because your web service uses web.config
You're probably confusing the scope of your class library.
Remember, your config, be it web.config, or app.config, is the config present in the HOSTING application. In this case your hosting application is the WebService, hosted of course by IIS, so your config file is the web.config.
If you had a console app which somehow used that class library (though probably not in an http handler context), then the config would be the app.config in the console app, not the app.config in your class library.
You need to put the configuration in your web.config file, not in assembly.dll.config: .NET does not (by design) read assembly.dll.config files.
Ever since upgrading to Visual Studio 2010, I'm running into an issue where the first web request of any type (WebRequest, WebClient, etc.) hangs for about 20 seconds before completing. Subsequent calls work quickly. I've narrowed down the problem to a proxy issue.
If I manually disable proxy settings, I don't experience this delay:
Dim wrq As WebRequest = WebRequest.Create(Url)
wrq.Proxy = Nothing
What's strange is that there are no proxy settings enabled on this machine in Internet Options. What I'm wondering is if there is a way to disable proxy settings for my entire project in one shot without explicitly disabling as above for every web object.
The main reason I want to be able to do this is that I'm trying to use an API (http://code.google.com/p/google-api-for-dotnet/) which uses web requests, but does not provide any way to manually disable proxy settings.
I have found some information suggesting that I need to add some proxy information to the app.config file, but I get errors building my program if I make an edits to that file.
Can anyone point me in the right direction?
Brent - that's the correct solution : adding a defaultProxy element to your application's configuration file.
So for a website, it's the web.config. For an .exe application, it's .config.
And those settings are also correct :-
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy enabled="false" useDefaultCredentials="false">
<proxy/>
<bypasslist/>
<module/>
</defaultProxy>
</system.net>
</configuration>
Instead of turning off the proxy setting altogether you can try using the bypasslist to turn it off for the servers that you're having problems with.
See http://msdn.microsoft.com/en-us/library/kd3cf2ex.aspx for details and a sample.
If you're having problems changing the app.config I suggest posting the errors and possibly the app.config as well.