4
votes

We have a silverlight project that uses RIA services. There is some code that I want to share between that project and a web service. I have to leave the code where it is now, i.e. I cannot share the code.

What I thought would be good is for the web service to call the RIA service. It will be sitting on the same server.

I went to my web service project, and added a service reference to the ria service. I clicked advanced and ticked the option for it to 'generate asynchronous operations'.

I thought it would be all good to go, but I got some warnings. The client code that it generated was missing any actual code relating to the asynchronous calls, and the app.config is also empty. Here are the warnings,

Warning 2   Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='CarServiceSoap']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_CarServiceSoap'] C:\Develop\DotNet\Trunk\Applications\WcfServices\CarTransmitter\CarTransmitter.Core\Service References\CarService\Reference.svcmap  1   1   CarTransmitter.Core

Warning 3   Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_CarServiceSoap']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:service[@name='CarService']/wsdl:port[@name='BasicHttpBinding_CarServiceSoap']   C:\Develop\DotNet\Trunk\Applications\WcfServices\CarTransmitter\CarTransmitter.Core\Service References\CarService\Reference.svcmap  1   1   CarTransmitter.Core

Warning 1   Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Referenced type 'CarData.Organisation, CarData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' with data contract name 'Organisation' in namespace 'http://schemas.datacontract.org/2004/07/CarData' cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='CarServiceSoap'] C:\Develop\DotNet\Trunk\Applications\WcfServices\CarTransmitter\CarTransmitter.Core\Service References\CarService\Reference.svcmap  1   1   CarTransmitter.Core
3

3 Answers

1
votes

Use the RIA services project option to create your service library. That creates 2 projects that are bound together (for code gen of the proxy objects). Both are effectively just libs (1 Silverlight and 1 .Net)

Link any RIA services client library to you Silverlight app. Then link the .web RIA project to your hosting web app (for the standard RIA use). You can also add the .web library to your Wcf service as a .Net lib (not consume it as a service).

If you did not create your main Silverlight project as a RIA services project you will need to move the settings across from the app.config file to your web.config file. If you already have the service support settings you only need to copy the db connection string across. The db connection string only should be needed for you Wcf project.

You should then be able to either use the server-side RIA calls (don't forget to add your own submitchanges calls as RIA does that behind the scenes once per batch of updates), or just use the data layer (EF etc) directly.

0
votes

Not finished completely, got quite a bit further along. The problems I am having now warrant a new question.

The solution to the above problem is to untick the option 'reuse types in referenced assemblies'. When you add service reference, you click the advanced button and you get the option 'reuse types in referenced assemblies'.

This is because I am sharing some code between the two projects I am using, and it was trying to 'reuse' objects I had on my side in the shared code. Instead I just wanted it to create proxy objects for me and not reuse those objects.

0
votes

Yes. It is possible to do.

  1. Create a library project
  2. Add LINQ to Entity model
  3. Add public class DomainService1 : LinqToEntitiesDomainService
  4. Check if your web.config looks like this one

    [?xml version="1.0"?] [configuration] [configSections] [sectionGroup name="system.serviceModel"] [section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" allowDefinition="MachineToApplication" requirePermission="false" /] [/sectionGroup] [/configSections]

    [system.webServer] [validation validateIntegratedModeConfiguration="false" /] [modules runAllManagedModulesForAllRequests="true"] [add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /] [/modules] [/system.webServer] [system.serviceModel] [domainServices] [endpoints] [add name="OData" type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /] [add name="soap" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /] [add name="JSON" type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /] [/endpoints] [/domainServices] [serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /] [/system.serviceModel]

    [connectionStrings] [add name="ASPNETDBEntities1" connectionString="metadata=res:///Model1.csdl|res:///Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=ASPNETDB;persist security info=True;user id=sa;password=yourpassword;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /][/connectionStrings] [system.web] [compilation debug="true"][assemblies][add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /][/assemblies][/compilation] [/system.web] [/configuration]

    1. Do WEB Publishing locally and test service link. Enjoy!