I have been struggling with creating a service which works for quite some time now. I originally had a service hosted from within my web application which ran my silverlight page, but I had read that will not work well in production. So currently, I have created a Service to do some data access for my silverlight app. The service runs great from my local computer. The service seems to work fine when hosted in IIS. However when I try to connect my silverlight client I get the following exception:
An error occurred while trying to make a request to URI 'http://computer.domain.local:8000/FormsDataServiceLibrary.FormsDataService.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.
Inner Exception: When deploying an Office solution, check to make sure you have fulfilled all necessary security requirements
Inner Exception: Use a certificate to obtain the required permission(s).
Inner Exception: If an assembly implementing the custom security object references other assemblies, add the referenced assemblies to the full trust assembly list.
After some research, I have tried upgrading the WebService.dll folder to Full Trust. I have messed around with different config files. I have literally worked on this problem straight for the last full week and have gotten nowhere. How do I fix this type of error?
There are so many files associated with this I don't even know what code to start posting. Lets start with the web service:
FormsDataService.cs
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class FormsDataService : IFormsDataService
{
public List
{
status = new CallResult();
try
{
FormDataDataContext spResult = new FormDataDataContext();
return spResult.SelectAllFormSets().ToList();
}
catch (Exception ex)
{
status.StatusCode = -1;
status.StatusMessage = "Exception occurred";
status.ExceptionDetails = ex.Message;
return new List
}
}
public List
{
status = new CallResult();
try
{
FormDataDataContext spResult = new FormDataDataContext();
return spResult.SelectFieldsPerFormSet(formSetId).ToList();
}
catch (Exception ex)
{
status.StatusCode = -1;
status.StatusMessage = "Exception occurred";
status.ExceptionDetails = ex.Message;
return new List
}
}
*** The rest of the Methods in that class look the same except they pull from different stored procedures***
Interface for above class:
[ServiceContract]
[SilverlightFaultBehavior]
public interface IFormsDataService
{
[OperationContract]
List
***Again same types of methods follow, The CallResult is simply somthing that holds my exceptions so I can read them in silverlight***
There is a DBML Class as well, that simply has stored procedures added and SerializationMode=Unidirectional
Web.Config
***So then I have my Client Files. I have simply created a connection with the Add Service Reference resulting in the following ServiceReferences.ClientConfig File***
contract="FormServiceReference.IFormsDataService" name="BasicHttpBinding_IFormsDataService" />
Please let me know what else you will need to come up with solutions for this. I am quite new at WCF so please bear with me. I would like to setup the security to be transparent. Once the silverlight application is loaded, I would simply like the users to be able to use the DB through it. This is run on an intranet so we are good on that front.
--Roman
roman hornichPosted Nov 18, 2011, 3:21 PM
Besides that I have a new symptom that was not there before. I needed to get some work done with my application so I reverted my code back to the point where I was hosting the application out of the website that hosts the silverlight page. I start up the silverlight app, and I get the same error as above (with the new localhost uri, of course). Everything was hosted out of VS not IIS for this new situation. The only difference is that it was hosted out of a different root folder.
I don't see this being a cache problem, I did attempt to clear my cache just in case but the URI is correct in both cases. I couldn't have changed anything within my client file on this application as I just pulled the app from a storage location, loaded it up, and started running it. I thought it could have something to do with me playing around Administrative tools, security policy... but I have removed everything I added there. I am stuck on this one, and now my silverlight application will not work no matter where I run the service from.
Either way, I have uploaded a version of my service below. I went ahead and posted everything that is in the root directory of the website. Please let me know if anyone has any ideas where to even start looking for where the error is coming from. I am to the point that I don't know where to start
***************************
While securing my service to takeout passwords and stuff I found the following file and attribute in the Bin Folder
FormsDataService.cs
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/FormsDataService/selectAllFormSets", ReplyAction="http://tempuri.org/FormsDataService/selectAllFormSetsResponse")]
I could not figure out how it got the tempuri.org in there. On a side note where is this being set from? Could this have to do with my problem?
***************************
--Roman
Priya LingePosted Nov 18, 2011, 12:13 AM
Hi Roman,
1.when your Silverlight application attempts to communicate with a 3rd party
remote server, a policy must exist (which is defined in either the "clientaccesspolicy.xml" or "crossdomain.xml" file) that allows this communication.
2.In order for Silverlight to call a remote resource on a different domain from where the XAP file was served such as a Web Service,the domain where the service must grant access
to the Silverlight application. The way this is done is using an XML file with the name "clientaccesspolicy.xml" or "crossdomain.xml".
3.These two files are located where the service being hosted.After putting these two files
at service side you will not get the crossdomain error.
clientaccesspolicy.xml file.
-
-
-
-
-
crossdomain.xml file
-
Please check below blog.
http://www.c-sharpcorner.com/Blogs/6161/clientaccesspolicy-xml-and-crossdomain-xml-files-in-silverli.aspx.
Hope this will help you.
Thanks.
Kunal NaikPosted Nov 17, 2011, 11:41 PM
You have to add these 2 files in your service project,
clientaccesspolicy.xml and crossdomain.xml
To know more about these files, refer following link,
Click Here
Hope this helps you.