views:

1297

answers:

2

General description

I am calling a Silverlight enabled WCF service from a Silverlight application. My service queries a database (SQL Server) and returns values from there. The problem is that the service uses other libraries that do the dirty database work and I get this exception when trying to use the service:

Exception

System.ServiceModel.CommunicationException was unhandled by user code   Message="An error occurred while trying to make a request to URI 'mysite/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."   StackTrace:
       at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
       at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
       at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
       at ODP_Silverlight.ODP.WCFServices.PropertySetWcfServiceClient.PropertySetWcfServiceClientChannel.EndGetPropertySet(IAsyncResult result)
       at ODP_Silverlight.ODP.WCFServices.PropertySetWcfServiceClient.ODP_Silverlight.ODP.WCFServices.PropertySetWcfService.EndGetPropertySet(IAsyncResult result)
       at ODP_Silverlight.ODP.WCFServices.PropertySetWcfServiceClient.OnEndGetPropertySet(IAsyncResult result)
       at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)   InnerException: System.Security.SecurityException
       Message=""
       StackTrace:
            at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
            at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
            at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
       InnerException: System.Security.SecurityException
            Message="Security error."
            StackTrace:
                 at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
                 at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
                 at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.<BeginOnUI>b__0(Object sendState)
            InnerException:

More info

If I remove the "using mylibs" from the using statements and just return some simple List<int> with a few numbers instead, the service works just fine.

Any insights anyone?

A: 

The using mylibs doesn't call any code. Only the code inside of mylibs does that. It would appear to be failing. You should test it.

Note that since this service is running on the server (not on the browser with SilverLight), the problem cannot be SilverLight permissions.

John Saunders
It actually is, but the problem occurs even if I comment out the code using it and just keep the using statement. This was the case when I reproduced the bug to copy paste the exception here.I found a way to work around this but it's not my first choice. If I add mylib.dll to the fully trusted assemblies of the machine, then it works, but I would like to avoid that solution. Wouldn't want to have the installer of the program to have to do that.You are probably right, the problem is with the service permissions as it can't access mylib.dll unless it is fully trusted.Any more thoughts?
sprite
Nonsense. The using statement does nothing at all. Did you also remove the reference to the DLL? Do you maybe have some reference to a type in the DLL but don't instantiate it? That might possibly fire static constructors. But all a using declaration does is provide an abbreviation. "using A;" means that you can refer to "A.B" simply as "B".
John Saunders
Well, the references to the mylib.dll existed in the project from the start. Even if you put the usings aside (I might be wrong on that), it still doesn't work when I try invoking methods and stuff from the referenced DLL but does work if I don't. Like I said, it does work with the reference dll if I add the dll to the "fully trusted assemblies" list at the machine level with "caspol -machine -af mylib.dll".
sprite
A: 

Have you implemented ClientAccessPolicy.xml and CrossDomain.xml on the WCF service? A CommunicationException like the one you are receiving could be caused by a missing ClientAccessPolicy.xml file or one that is not allowing your Silverlight client access to the service.

DaveB
Hello DaveB,I have a ClientAccessPolicy.xml file in place. I even know it's working since if I remove it even returning a simple List< int > doesn't work because the service is not accessable. My problem only begins if I use other libraries (C# - other projects in same solution in VS2008). If I keep all the logic inside the project hosting the service then it works, but I wouldn't like to do that. I already have a dll doing all the DB work and would like to reuse it.Any other thoughts?Thanks...
sprite
Have you tested the service with WcfTestClient? Are there exceptions from there as well? Can you view the .svc file in a browser OK? Can you click on the WSDL link and confirm it works?I am working on a project right now that has the same structure as you describe. Set a referenece from the service implementation project to the data access project and you should not get this error. Is all the data access local? Do you can any web services from the data access layer?
DaveB