Cross Domain Exclusion Using WcfSvcHost

and sorry for another cross domain question.

I fight this all day and I'm at the boiling point.

I have a Silverlight application project (SLApp1), a web project to host Silverlight (SLApp1.Web), and a WCF project (SLWcfService).

Now I am building everything together, and all projects are in one solution. The web project is hosted in Visual Studio, and the WCF service is hosted in WcfSvcHost.

The problem is that the website and wcf are hosted separately, there is a cross-domain problem, so every time a Silverlight application tries to make a WCF call, a cross-domain exception is thrown.

I tried:

  • Adding clientaccesspolicy.xml to C: \ inetpud \ wwwroot
  • Using webHttpBinding and the presence of the ReadPolicy method in the service

The problem is that I'm still developing a solution, and so publishing a service and then posting it in IIS is simply not a possible solution.

Why should it be so incredibly difficult?

Please, help!

Reference material:

My App.config:

<system.serviceModel> <services> <service name="Test.Service1" behaviorConfiguration="Test.Service1Behavior"> <host> <baseAddresses> <add baseAddress="http://localhost:8055" /> </baseAddresses> </host> <endpoint address="Service1" binding="basicHttpBinding" contract="Test.IService1"/> <endpoint address="" binding="webHttpBinding" behaviorConfiguration="webHttpBehavior" contract="Test.WCFService.IClientAccessPolicy" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="Test.WCFService.Service1Behavior"> <serviceMetadata httpGetEnabled="True" /> <serviceDebug includeExceptionDetailInFaults="False" /> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="webHttpBehavior"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> </system.serviceModel> 
+4
source share
4 answers

Ok, somehow I worked using the REST trick and webHttpBinding. I made changes to the way I read clientaccesspolicy from a file that was read, just using the cons line.

This is how I solved the problem:

App.config:

  <system.serviceModel> <services> <service name="Symphony.Server.WCFService.Service1" behaviorConfiguration="Symphony.Server.WCFService.Service1Behavior"> <host> <baseAddresses> <add baseAddress="http://localhost:8055" /> </baseAddresses> </host> <endpoint address="Service1" binding="basicHttpBinding" contract="Symphony.Server.WCFService.IService1"/> <endpoint address="" binding="webHttpBinding" behaviorConfiguration="webHttpBehavior" contract="Symphony.Server.WCFService.IClientAccessPolicy" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="Symphony.Server.WCFService.Service1Behavior"> <serviceMetadata httpGetEnabled="True" /> <serviceDebug includeExceptionDetailInFaults="False" /> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="webHttpBehavior"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> 

IClientAccessPolicy.cs

 [ServiceContract] public interface IClientAccessPolicy { [OperationContract, WebGet(UriTemplate = "/clientaccesspolicy.xml")] Stream GetPolicy(); } 

Service1.cs

 public class Service1 : IService1, IClientAccessPolicy { public IList<string> GetData(string value) { //Some logic } [OperationBehavior] public Stream GetPolicy() { const 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>"; if (WebOperationContext.Current != null) WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml"; return new MemoryStream(Encoding.UTF8.GetBytes(result)); } 

Note: You must include System.ServiceModel.Web as a reference

thanks

0
source

Although I'm not sure if this will fix your problem, I will show you how I managed to install a similar solution layout and maybe the steps will have some recommendations.

I installed the solution with a silverlight project (domainexception), a web project (domainexception.Web) and a wcf service (WcfServiceLibrary1). I made the Service1 endpoint the base HttpBinding, as in your App.config.

Then I added the service link to the silverlight project and built it with the following address:

" http: // localhost: 8731 / Design_Time_Addresses / WcfServiceLibrary1 / Service1 / "

Trying to run it like this, I also ran into a cross-domain policy issue.

Then I added the webHttpBinding and method to it and still found that it was not working.

So finally, I changed the base address from one above to

http: // localhost: 8731

and he worked.

In the end it worked. So that's how it was at the end.

App.config

  <system.serviceModel> <services> <service name="WcfServiceLibrary1.Service1" behaviorConfiguration="WcfServiceLibrary1.Service1Behavior"> <host> <baseAddresses> <add baseAddress = "http://localhost:8731/" /> </baseAddresses> </host> <endpoint address ="Service" binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1"> <identity> <dns value="localhost"/> </identity> </endpoint> <endpoint address="" binding="webHttpBinding" behaviorConfiguration="policyBehavior" contract="WcfServiceLibrary1.IService1"/> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <endpointBehaviors> <behavior name="policyBehavior"> <webHttp /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="WcfServiceLibrary1.Service1Behavior"> <serviceMetadata httpGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="False" /> </behavior> </serviceBehaviors> </behaviors> 

ServiceReferences.ClientConfig

 <configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <security mode="None" /> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://localhost:8731/Service" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" /> </client> </system.serviceModel> 

and my web policy call:

Interface

 [OperationContract, WebGet(UriTemplate="clientaccesspolicy.xml")] Stream ReturnPolicy(); 

the code

 public System.IO.Stream ReturnPolicy() { string file = @"<?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 new MemoryStream(Encoding.UTF8.GetBytes(file)); } 
+1
source

I also faced the same problem. What I came to the conclusion was that it was time to refer to the WCFervice project DLL in WebProject (Hosting Silverlight Control) and changed its web.config to match WCFService. Then, instead of using the WcfSvcHost Reference, I used the link from WebProject, it was a workaround that I used.

But, in short, itโ€™s a little difficult to apply the client access policy to the service hosted by WCFSvcHost.

0
source

PolicyService (REST) โ€‹โ€‹in a WCFService project can solve this issue. Such a service allows for sending xml (clientAccessPolicy) to Response. for example if your service url is: http: // localhost: [port] /Design_Time_Addresses/MyService.svc

Then the URL of the PolicyService will be: http: // localhost: [port] /clientaccesspolicy.xml (this REST request will send clientaccesspolicy to Response for SilverlightClient).

Here is a link on how to create such a PolicyService: http://social.msdn.microsoft.com/Forums/en/wcf/thread/d145a38f-b9bb-4c8e-9eab-b728dacc19df

0
source

Source: https://habr.com/ru/post/1302233/


All Articles