Monday, March 9, 2009

Setup Multiple WCF Service Reference Part 1

This is how I have setup a multiple "Services" (Interfaces) within in a single host.  Way I understand the WCF is that it acts as a virtual .Dll.  As such, you can practically place every routine in the WCF space.  

Scenarios:

public
class
Service1 : IService1

{


public Service2 Service2 { get; set; }


public Service3 Service3 { get; set; }


public Service4 Service4 { get; set; }

}

You want to able to do some routines that are required by Service2..4.   Let's say that each one of them has (add/update, delete, get) functions.  You could insert them into the IService1.  However, you would have too many methods.  So, I thought of creating separate services for separate classes.  I am sure there are better ways.  I do not know the better ways as of today (03/05/2009).  I have not been able to use generics or something bit clever or elegant.

This is what I came up for my self-technical constraints.

<system.serviceModel>

<bindings />

<services>

<service
behaviorConfiguration="WCFLibrary.Service1Behavior"


name="WCFLibrary.MyService">

<clear />

<endpoint
binding="wsHttpBinding"
contract="WCFLibrary.IService1"


listenUriMode="Explicit">

<identity>

<dns
value="localhost" />

identity>

endpoint>

<endpoint
address="mex"
binding="mexHttpBinding"
name="mex"
contract="IMetadataExchange" />

<host>

<baseAddresses>

<add
baseAddress="http://localhost:8080/MyService1" />

</baseAddresses>

</host>

</service>

<service
behaviorConfiguration="WCFLibrary.Service1Behavior"


name="WCFLibrary.MyService2">

<endpoint
address=""
binding="wsHttpBinding"
bindingConfiguration=""


contract="WCFLibrary.IService2" />

<endpoint
address="mex"
binding="mexHttpBinding"
name="mex"
contract="IMetadataExchange" />

<host>

<baseAddresses>

<add
baseAddress="http://localhost:8080/MyService2" />

</baseAddresses>

</host>

</service>

<service
behaviorConfiguration="WCFLibrary.Service1Behavior"


name="WCFLibrary.MyService3">

<endpoint
address=""
binding="wsHttpBinding"
bindingConfiguration=""


contract="WCFLibrary. IService3" />

<endpoint
address="mex"
binding="mexHttpBinding"
name="mex"
contract="IMetadataExchange" />

<host>

<baseAddresses>

<add
baseAddress="http://localhost:8080/MyService3" />

</baseAddresses>

</host>

</service>

<service
name="WCFLibrary.MyService4"
behaviorConfiguration="WCFLibrary.Service1Behavior">

<endpoint
address=""
binding="wsHttpBinding"
bindingConfiguration=""


contract="WCFLibrary.IService4" />

<endpoint
address="mex"
binding="mexHttpBinding"
name="mex"
contract="IMetadataExchange" />

<host>

<baseAddresses>

<add
baseAddress="http://localhost:8080/MyService4" />

</baseAddresses>

</host>

</service>

</services>


 

<behaviors>

<serviceBehaviors>

<behavior
name="WCFLibrary.Service1Behavior">

<serviceMetadata
httpGetEnabled="true" />

<serviceDebug
includeExceptionDetailInFaults="false" />

</behavior>

</serviceBehaviors>

</behaviors>

</system.serviceModel>

Wednesday, March 4, 2009

WCF "The target assembly contains no service types"

WCF Error

"The target assembly contains no service types.  You may need to adjust the Code Access Security policy of this assembly."


 

This is because you have left out your WCF interface.


 

If you have a IWebService.cs and a WebService.cs...  that does WebService: IWebService but for whatever reason you took out the IWebService... like I have done before.. you will get this error.


 

The answer is to put that back in.  You can create interface from your class from class diagram.  Use class diagram almost all the time.  It is very good tool to engineer your code.  It is a must.


 

On the web, there was a suggestion of taking out  {3D9AD99F-2412-4246-B90B-4EAA41C64699};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} from your project file..Don't do it.  I think these are the paired Guid for the WS client and the WS host.  I could be wrong.


 

Good luck.