I was wondering if there is anybody out there that has a fix for the problem some people have. When you self-host a WCF service in, for exmaple, a console application, there is no webroot to place the crossdomain.xml and clientaccesspolicy.xml files in.
In Silverlight 2 Beta 1, there was a workaround which can be found here:
http://blogs.msdn.com/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx
Is there anyone who has a simliar fix for beta 2? I have no clear reason why it shouldn't work. I updated the crossdomain.xml and clientaccespolicy.xml files to meet the beta 2 requirements, but it still gives me a crossdomain error.
When I browse to the xml files in the root, the new xml files ARE displayed, so I have no clue why silverlight shouldn't get them?
WCF Self host cross domain
If this post helped you, please mark it as answer! It helps other people too.
Are you sure the problem you are having is the policy file? Since virtually all problems with service connections come back as a 404, it can be hard to tell the exact problem sometimes.
I assume you can browse to the service itself and it is working fine? Does your policy file have any restrictions on it or is it "wide open"? I recommend throwing in a completly new one with no restrictions to ensure that there is no problem there.
Can you create a Service Reference to it successfully from your SL app? If not the policy file might not be the problem.
Also, you don't need both a crossdomain.xml and a clientaccesspolicy.xml file in place for SL to access it, just the clientaccesspolicy is needed.
Are you sure the problem you are having is the policy file? Since virtually all problems with service connections come back as a 404, it can be hard to tell the exact problem sometimes.
Yes, at least I get a cross domain error while both XML files are accessible.
johnnystock
I assume you can browse to the service itself and it is working fine? Does your policy file have any restrictions on it or is it "wide open"? I recommend throwing in a completly new one with no restrictions to ensure that there is no problem there.
Both are wide open, and I can browse to them. Same as the service, it shows up nicely in the browser.
johnnystock
Can you create a Service Reference to it successfully from your SL app? If not the policy file might not be the problem.
Yes. It detects the service. Other consumers (WPF app) work with the service, so the service itself is working.
If this post helped you, please mark it as answer! It helps other people too.
Take a look at this tread. The guy is doing exactly the same thing as you do. Follow each steps I put there, you should be able to understand how this whole thing works.
Take a look at this tread. The guy is doing exactly the same thing as you do. Follow each steps I put there, you should be able to understand how this whole thing works.
Not exactly. He use IIS to host his WCF service, I use self-hosting. I used the following method (only a snippet of it) to emulate the crossdomain.xml.
return
new MemoryStream(Encoding.UTF8.GetBytes(result));
}
The code above worked fine in SL2B1, but since SL2B2, the above does not seem to work. I am looking for a similar way to emulate both xml files, instead of having to host a website just for those 2 XML files. I want to selfhost without any extra XML files
or webservers to make it accessible for Silverlight.
If this post helped you, please mark it as answer! It helps other people too.
No, if you read the thread carefully, you will understand he does not even have IIS installed. He is just using Dev Web server, just like you do.
You don't have to mess up with clientaccesspolicy.xml file if you use Dev Web server. It should be under one domain call, not cross-domain call if you can make sure the page and the service is running under the same port number.
Sally Xu
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
No, if you read the thread carefully, you will understand he does not even have IIS installed. He is just using Dev Web server, just like you do.
No I don't use the Dev Web server. I start my service from a Console application. No IIS instantce involved at all. On the Silverlight side tho, there is, ofcourse.
With SL2B1 I could start the console application on one PC (With no IIS installed nor VS2008 running) and I could call the service from within a SL application on an other computer. So it worked perfectly. I just need to tune the WCF service or the console
host application to make it work with SL2B2.
If this post helped you, please mark it as answer! It helps other people too.
Oh, I got it. So you use a Console app as your Service server. Then I think that is a cross-domain call. So where did you put your cross-domain policy file in beta 1? And have you updated that file after beta 2? There is one more attribute you need to have
in that file. If not, here is the new one:
If you look a few posts back, you will see that I posted a part of the WCF service that uses a WebGet method to emulate a webserver. Sending the XML file as a stream is basically what a webserver does, and this works. If you browse to the URL in your browser,
the XML file is displayed. This way you can make your WCF service act like a webserver.
Above worked in SL2B1, a service that just did reguar stuff but had a little webserver extension to emulate both XML files. Problem is, even with both updated XML files, I get a cross domain error. Even though I can do the rest. Even calls from other applications
consuming the service.
So my problem is, how do I debug this? I don't have any clue what is going wrong..
If this post helped you, please mark it as answer! It helps other people too.
Roet
Member
221 Points
66 Posts
WCF Self-host crossdomain fix?
Jun 16, 2008 11:37 AM | LINK
Hello,
I was wondering if there is anybody out there that has a fix for the problem some people have. When you self-host a WCF service in, for exmaple, a console application, there is no webroot to place the crossdomain.xml and clientaccesspolicy.xml files in.
In Silverlight 2 Beta 1, there was a workaround which can be found here:
http://blogs.msdn.com/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx
Is there anyone who has a simliar fix for beta 2? I have no clear reason why it shouldn't work. I updated the crossdomain.xml and clientaccespolicy.xml files to meet the beta 2 requirements, but it still gives me a crossdomain error.
When I browse to the xml files in the root, the new xml files ARE displayed, so I have no clue why silverlight shouldn't get them?
WCF Self host cross domain
johnnystock
Contributor
2295 Points
362 Posts
Re: WCF Self-host crossdomain fix?
Jun 16, 2008 01:11 PM | LINK
Are you sure the problem you are having is the policy file? Since virtually all problems with service connections come back as a 404, it can be hard to tell the exact problem sometimes.
I assume you can browse to the service itself and it is working fine? Does your policy file have any restrictions on it or is it "wide open"? I recommend throwing in a completly new one with no restrictions to ensure that there is no problem there.
Can you create a Service Reference to it successfully from your SL app? If not the policy file might not be the problem.
Also, you don't need both a crossdomain.xml and a clientaccesspolicy.xml file in place for SL to access it, just the clientaccesspolicy is needed.
I hope something in this helps,
Microsoft Silverlight MVP and RIA Developer at Ascentium
Co-Author of Silverlight 2 in Action
Roet
Member
221 Points
66 Posts
Re: WCF Self-host crossdomain fix?
Jun 16, 2008 03:01 PM | LINK
Yes, at least I get a cross domain error while both XML files are accessible.
Both are wide open, and I can browse to them. Same as the service, it shows up nicely in the browser.
Yes. It detects the service. Other consumers (WPF app) work with the service, so the service itself is working.
sladapter
All-Star
43607 Points
7907 Posts
Re: WCF Self-host crossdomain fix?
Jun 16, 2008 03:10 PM | LINK
Take a look at this tread. The guy is doing exactly the same thing as you do. Follow each steps I put there, you should be able to understand how this whole thing works.
http://silverlight.net/forums/p/18169/61224.aspx#61224
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
Roet
Member
221 Points
66 Posts
Re: WCF Self-host crossdomain fix?
Jun 16, 2008 03:21 PM | LINK
Not exactly. He use IIS to host his WCF service, I use self-hosting. I used the following method (only a snippet of it) to emulate the crossdomain.xml.
[ServiceContract]
public interface IPolicyRetriever
{
[OperationContract, WebGet(UriTemplate = "/crossdomain.xml")]
Stream GetPolicy();
}
public Stream GetPolicy()
{
string result = @"<?xml version=""1.0""?>
<!DOCTYPE cross-domain-policy SYSTEM ""http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"">
<cross-domain-policy>
<allow-access-from domain=""*"" new header stuff here (only got the old snippet at my pc here) />
</cross-domain-policy>";
WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
return new MemoryStream(Encoding.UTF8.GetBytes(result));
}
The code above worked fine in SL2B1, but since SL2B2, the above does not seem to work. I am looking for a similar way to emulate both xml files, instead of having to host a website just for those 2 XML files. I want to selfhost without any extra XML files or webservers to make it accessible for Silverlight.
sladapter
All-Star
43607 Points
7907 Posts
Re: WCF Self-host crossdomain fix?
Jun 16, 2008 03:26 PM | LINK
No, if you read the thread carefully, you will understand he does not even have IIS installed. He is just using Dev Web server, just like you do.
You don't have to mess up with clientaccesspolicy.xml file if you use Dev Web server. It should be under one domain call, not cross-domain call if you can make sure the page and the service is running under the same port number.
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
Roet
Member
221 Points
66 Posts
Re: WCF Self-host crossdomain fix?
Jun 16, 2008 03:36 PM | LINK
No I don't use the Dev Web server. I start my service from a Console application. No IIS instantce involved at all. On the Silverlight side tho, there is, ofcourse.
With SL2B1 I could start the console application on one PC (With no IIS installed nor VS2008 running) and I could call the service from within a SL application on an other computer. So it worked perfectly. I just need to tune the WCF service or the console host application to make it work with SL2B2.
sladapter
All-Star
43607 Points
7907 Posts
Re: WCF Self-host crossdomain fix?
Jun 16, 2008 03:52 PM | LINK
Oh, I got it. So you use a Console app as your Service server. Then I think that is a cross-domain call. So where did you put your cross-domain policy file in beta 1? And have you updated that file after beta 2? There is one more attribute you need to have in that file. If not, here is the new one:
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>
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
Roet
Member
221 Points
66 Posts
Re: WCF Self-host crossdomain fix?
Jun 16, 2008 08:45 PM | LINK
If you look a few posts back, you will see that I posted a part of the WCF service that uses a WebGet method to emulate a webserver. Sending the XML file as a stream is basically what a webserver does, and this works. If you browse to the URL in your browser, the XML file is displayed. This way you can make your WCF service act like a webserver.
Above worked in SL2B1, a service that just did reguar stuff but had a little webserver extension to emulate both XML files. Problem is, even with both updated XML files, I get a cross domain error. Even though I can do the rest. Even calls from other applications consuming the service.
So my problem is, how do I debug this? I don't have any clue what is going wrong..
Allen Chen –...
Star
13897 Points
1809 Posts
Microsoft
Re: WCF Self-host crossdomain fix?
Jun 18, 2008 06:29 AM | LINK
Hi:
Please refer to my reply in this thread:
http://silverlight.net/forums/p/16839/57457.aspx
It's for Beta 1 so you need to change the content of policy file.
Regards
Allen Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.