Using a WCF Service Library from Silverlight - wcf

I've added a WCF Service Library to a Silverlight project. But when I try calling a method on the service I get a CommunicationException complaining about accessing a service in a cross-domain way.
I've tried adding both a crossdomain.xml and clientaccesspolicy.xml to the service library project, but it doesn't help.
Any idea what I'm doing wrong?

You mention that the policy files are going into the service library, have you checked they get placed into the correct place within the website?
Try running up fiddler to see what the web site is actually returning when the service is called.

Copy CrossDomain.xml and clientpolicy.xml files in C:\Inetpub\wwwroot path. :)

Related

What is the advantage of using a WCF service instead of a WCF library if I am going to host a WCF service in IIS?

I understand what the differences are between a WCF Library and a WCF Service. I typically will build a WCF Library and reference it from a WCF Service. But if I am going to deploy to IIS, why not just deploy the WCF Library and forget about creating the WCF Service. Does it matter which one I deploy?
Answering my own question: From what I have read it doesn't seem to matter much if you deploy a wcf library or a wcf service. If you deploy the library, make sure that you copy the contents of your app config file to the web config file. The wcf service does also provide an svc file, but you only need that if you are using an earlier version of .net framework other than 4.0 or later. If you deploy the service instead of the library, the App config file for the service will pass the content onto the Web.config file when it is deployed. I am pretty sure that these are the only differences. The two people that replied to my question didn't really take the time to read and understand the question. It got marked as a possible duplicate, which clearly it is not.

Self hosted cross domain WCF service called from silverlight hosted in sharepoint

as the title already states I am trying to call a self hosted WCF service (hosted in a windows service) from a silverlight 4.0 application which is hosted in sharepoint 2010. I use the basicHttpBinding and I already tried a lot of things as suggested here:
http://www.dotnetfunda.com/articles/article416.aspx
or here
http://blogs.msdn.com/b/carlosfigueira/archive/2008/03/07/enabling-cross-domain-calls-for-silverlight-apps-on-self-hosted-web-services.aspx
but none of them worked I still get the error:
An error occurred while trying to make a request to URI 'serviceuri'. 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.
The inner exception states:
when deploying an Office solution, check to make sure you have fullfilled all security requirements.
The two files clientaccesspolicy.xml and crossdomain.xml are accessible on http://myserver/clientaccesspolicy.xml and http://myserver/crossdomain.xml
Does anybody have an idea on how to solve this?
All these things helped me out. But the biggest thing for me was turning on Fiddler and tracing the request/responses from Sharepoint + Silverlight. I was getting a 502 error back for some reason. I noticed that my Url in my code was "http://localhost:", however the request from silverlight was "http://[servername]:" you would think that this should work, however it didn't.
I remembered I had run into issues before where "localhost" was giving me problems, thus what I did was to edit my Host file from /windows/system32/drivers/etc and simply add the line::
127.0.0.1 [servername]
I did a iisreset, I left fiddler running and I unchecked the Enable IPv6 option (Tools->Fiddler Options) and everything started working. The Clientaccesspolicy.xml could be accessed, and sharepoint + silverlight could call out into the wcf world :)!!!
There was one major issues however, when you turn Fiddler off, it stopped working... Now I have to figure this one out...
I hope this hellps you.

Creating a simple wcf service publishing it to my webhotel, and get it to work

This seems to be a recurring problem to me. I want to get started doing wcf services. I create a new Wcf Service Library, compile it, and publish it using FTP to my providers webhotel. But its not working. I somehow cant get access. I dont want some fancy security model - i just want to get a hole through to my simple webservice. Seems that its the part when i publish it to my webhotel (in a subdomain) that breaks the webservice - its working perfectly when starting it locally.
How to proceed anyone?
Often you need confguration information to host a service. If the service is hosted in IIS, then you need that configuration in web.config. Are you updating Web.config properly? Some hosters don't allow it.
To address this problem you can set up your IIS-hosted WCF service to read its config data from elsewhere.
I wrote a bit about my findings, this solved my issue: http://www.vikingworks.dk/post/WCF-Service-on-hosted-environment.aspx

WCF, Silverlight: clientaccesspolicy.xml not being found

I"m trying to connect my Silverlight application to a WCF service that I'm hosting myself. I've created a clientaccesspolicy.xml file, and placed it in the service host project's root, but when I try to hit the service, my http sniffer says it can't be found. Specifically the file it's looking for is http://localhost:8080/clientaccesspolicy.xml.
I'm running the server and the silverlight app in debug mode in Visual Studio 2010. Do I need to put the file somewhere else?
The clientaccesspolicy.xml file must be in the root of the domain where the service is hosted. You may already have it there but the virtual path of the web site or web application from the property page will need to be changed to "/"
See this page
for more information.
I did not understand how you're hosting your WCF service?
Is it hosted in a asp.net application or a windows host (self-hosting)? If the latter is the case, you may have to implement a clientaccesspolicy service that provides the content of the clientaccesspolicy.xml file on request.
For example like this.

How to communicate between two applications?

I have created a library which reads the app.config file and gets the type of WCF service in which it is called.
Now, I have a separate console application, I want that this library informs the console application about the type it found in the WCF service so that the console application can host it.
It is useful because then I will just add my library in any WCF service and call its method and it will then inform my console application and it will host it.
Please give me an idea on this problem.
I have to agree with Marc, but this is perhaps related to your question regarding ServiceHost, but what is the purpose of your console application?
Is it acting as a host or as client (consumer of the services). If its a host I would simply add the appropraite configuration in the app.config?
HTH
Phil'