roman hornich

roman hornich

  • NA
  • 3
  • 3.2k

WCF Service which queries the DB for a silverlight client

Nov 17 2011 4:00 PM

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<SelectAllFormSetsResult> selectAllFormSets(out CallResult status)
        {
            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<SelectAllFormSetsResult>();
            }
        }

        public List<SelectFieldsPerFormSetResult> selectFieldsPerFormSet(Int64 formSetId, out CallResult status)
        {
            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<SelectFieldsPerFormSetResult>();
            }
        }

 

*** 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<SelectAllFormSetsResult> selectAllFormSets(out CallResult status);

 

***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 <of Service>

<?xml version="1.0"?>
<configuration>

  <configSections>
  </configSections>
  <connectionStrings>
    <add name="FormsDataServiceLibrary.Properties.Settings.SIMS_TESTConnectionString" connectionString="[DbConStr]" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <compilation debug="true"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="FormsDataServiceLibrary.FormsDataServiceBehavior" name="FormsDataServiceLibrary.FormsDataService">
        <endpoint address="" binding="basicHttpBinding" contract="FormsDataServiceLibrary.IFormsDataService">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://[ServerName]:8000/FormsDataServiceLibrary.FormsDataService.svc"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="FormsDataServiceLibrary.FormsDataServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

 

***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***

 

<configuration>
    <system.serviceModel>
      <bindings>
        <basicHttpBinding>
          <binding name="BasicHttpBinding_IFormsDataService" maxBufferSize="2147483647"
            maxReceivedMessageSize="2147483647">
            <security mode="None" />
          </binding>
        </basicHttpBinding>
      </bindings>
      <client>
        <endpoint address="http://[ServerName]:8000/FormsDataServiceLibrary.FormsDataService.svc"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFormsDataService"
          contract="FormServiceReference.IFormsDataService" name="BasicHttpBinding_IFormsDataService" />
      </client>
    </system.serviceModel>
</configuration>

 

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


Answers (3)