Unhandled CommunicationException in Silverlight 3-Tier App

Unhandled CommunicationException in Silverlight 3-Tier App

Old forum URL: forums.lhotka.net/forums/t/10297.aspx


thaehn posted on Friday, April 22, 2011

I am writing a 3-tier Silverlight app.  I fetch the data from the database and return the result back to the UI app and get a CommunicationException in this EndFetch method of the Service Reference class (Reference.cs):

System.ServiceModel.CommunicationException was unhandled by user code
  Message=An error occurred while trying to make a request to URI 'http://localhost:56515/WcfSlPortal.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.EndCall(String action, Object[] outs, IAsyncResult result)
       at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
       at Csla.WcfPortal.WcfPortalClient.WcfPortalClientChannel.EndFetch(IAsyncResult result)
       at Csla.WcfPortal.WcfPortalClient.Csla.WcfPortal.IWcfPortal.EndFetch(IAsyncResult result)
       at Csla.WcfPortal.WcfPortalClient.OnEndFetch(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__DisplayClass4.<BeginOnUI>b__1(Object sendState)
            InnerException:

Any ideas what I am doing wrong?

RockfordLhotka replied on Friday, April 22, 2011

The exception contains the answer:

"An error occurred while trying to make a request to URI 'http://localhost:56515/WcfSlPortal.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."

If you call a service located at a different URL than the location the SL app came from, that other service needs a cross-domain policy file. You can find numerous examples of this file in the CSLA samples, or with a simple Internet search.

thaehn replied on Friday, April 22, 2011

Rocky,

It is running from the same web project as the silverlight control (the one auto generated when the silverlight project was created).  It is all running on the development server in Visual Studio.

Todd

RockfordLhotka replied on Saturday, April 23, 2011

The most common issue is that it is the SL project that is set as the startup project, not the web project. In that case Visual Studio runs the SL app in a separate URL from the web app, causing the issue you are seeing.

thaehn replied on Monday, April 25, 2011

Rocky,

That was not the problem.  I had the wrong port number on one of the endpoints in the web config file, which when corrected fixed the problem.  Thank you for your help.  I appreciate the way you monitor this forum and respond to questions so quickly.  When I am hung up on a problem and can't go on, it is very frustrating.

Todd

Copyright (c) Marimer LLC