Must Contract:Service Ratio be 1:1?

Nov 12, 2007 at 4:57 PM
I'm still very new to WSSF so sorry if this is another naive question.

It appears that in a Service Model, a Service can implement only one Service Contract, and a Service Contract can be implemented by only one Service. In other words, the relationship of Service Contract to Service must be 1:1. But in WCF the relationship is M:M: a Service can implement many Service Contracts, and a Service Contract can be implemented by many Services. Can I represent this M:M relationship with the Service Factory?

Suppose for instance I want a single Service to implement multiple Service Contracts. Can I model this arrangement in a Service Model? If not, can I at least cause it to generate code this way?

Thanks,

Sir Eel
Nov 12, 2007 at 5:12 PM
Edited Nov 12, 2007 at 5:28 PM
Don can provide more input here as to why we do this.

As an aside... This is a constraint in the ServiceReferencesServiceContract domain relationship on the DSL. To change this you would have to modify the DSL and then update the TT templates that generate from the DSL. This wouldn't be that hard but it would require recompilation of the factory.

Ade

Jan 14, 2008 at 11:01 AM
Hello.

Any updates how this can be done?

Keirol
Jan 15, 2008 at 4:52 PM
This is quite a pretty involved change, but if you feel in good shape to tackle this one, then here are the main steps you can follow as a head start:
Steps:
  1. Open, file: Service Contract DSL\Dsl\CustomCode\Connection\ConnectionBuilder.cs
  2. Comment lines, 99 and 100 (both Ifs)
  3. Open DslDefinition.dsl file on ServiceContractDsl project and edit "ServiceReferencesServiceContract" relation shape. Select "ServiceContracts" link on the left hand side and Set property "Multiplicity" to "1..*".
  4. Run "Transforms All Templates" from Solution Explorer toolbar.
  5. Build the project.
  6. Now fix all errors regarding the API changes, most of them because of the renamed "Microsoft.Practices.ServiceFactory.ServiceContracts.ServiceReferencesServiceContract" to "Microsoft.Practices.ServiceFactory.ServiceContracts.ServiceReferencesServiceContracts"
  7. Open "ServiceModelConfigurationStrategy" in Microsoft.Practices.ServiceFactory.Extenders.HostDesigner.Wcf project and make the appropriate changes.
  8. Open the ServiceContract and ServiceImplementation templates in "Service Contract DSL\Dsl\TextTemplates\WCF\CS\" and make the appropriate changes since the "CurrentElement.ServiceContract" changed to "CurrentElement.ServiceContracts" so should consider all the contracts and add all the interfaces to the service implementation.
  9. Reset the Experimental Hive.
  10. Rebuild solution
  11. Register Package
  12. Open a new sln in the Experimental Hive and test the changes.
Notice that you might find some other issues but if you get it to the last step, chances are that you will find the fix.
Jan 16, 2008 at 1:10 AM
I'll try to experiment on the steps and would give you feedback. Thanks so much!
May 9, 2008 at 1:04 AM
Not sure if anyone has implmented this scenario. I have and it is far more complex than this. Getting a new binary installation created is a complex challenge. I can supply the changes required for this if anyone would like to have it. It will spare you the pain I went through.
May 9, 2008 at 3:22 AM
I would like to know the steps. For creating the binary installation for the changes you made on your service factory, I can help you on that one. I have made it worked before but that would mean you would need to generate alot of guid values for each new item that you add in your service factory solution. Also, you have to get a Package Load Key(PLK) here --> http://msdn.microsoft.com/en-us/vsx2008/products/bb964519.aspx. You can register for a free package load key using your live passport. You can see under Setup folder the files you need to update for that one.

Hope you would post the steps for the M:M ratio to work. Thanks.
May 13, 2008 at 2:28 AM

Keirol,

Steps to add multiple service contracts to a service.

1. Open DslDefinition.dsl in the ServiceContractDsl project. Find ServiceReferencesServiceContracts shape. Select the ServiceContracts link.
Change multiplicity to 1..*. Save the changes.

2. On the Solution Explorer tool bar click on the transform all templates icon.

3. Build the ServiceContractDsl project. Don’t panic there will be errors.

4. The largest change involves the Microsoft.Practices.ServiceFactory.ServiceContracts.ServiceReferencesServiceContract changes to
Microsoft.Practices.ServiceFactory.ServiceContract.ServiceReferencesServiceContracts. Fix all of them.

5. In the Microsoft.Practices.ServiceFactory.Extenders.HostDesigner.Wcf project the ServiceModelConfigurationStrategy class needs a foreach loop
 added so the factory will loop through the all of the service contracts in the service. I think it’s around line 90. You will need to add a loop.
 foreach (var serviceContract in service.ServiceContracts){} It should encapsulate everything up to the finally block. There are areas in the loop
 that also need to be updated they will be apparent. Look in the updated project files for reference.

6. The TextTemplates in the ServiceContractDsl project are next. This is the funky part. The <# #> delimiters are confusing. I would just refer the
 my updated project to see what needs to be changed.

7. The PLK's are the tricky part. There are several places that are update automatically, however the installation project does not update the Model
 project correctly. In HostDesignerRegistry.wxs file the Company name does not update automatically. In each of the *.Package projects there is a generatedcode
 folder containing a package.tt file that has the ProvideLoadKey attribute and I had to change the company name and the package name here. It looks
 like the names are supposed to come from Constants.tt but if you change them there the registry values do not change. I have not had the time to figure out why.

8. You are welcome to use my modified guidance package but please change the company name.

If they dont make sense. Feel free to email me. lgiambalvo at DigitalMailer dot com

I have uploded the project to my public folder on Windows live sky drive. Here is the url. http://cid-9b21f9f62e53ee1f.skydrive.live.com/browse.aspx/Public 
It should be there in about 30 minutes.

Lenny