I've got a few types that are commonly used between several different WCF services. I'd like to be able to expose those types on a single endpoint and have them reusable against all the services. They're identical (indeed, they're defined by a single DataContract) so I'd have thought that would be possible but I just can't work out how to do it.
E.G.:-
My Shared Type. Defined in a single DataContract.
Service1 exposing the type:-
Service2 exposing the type:-
And here's the sort of stuff I'd like to be able to do in the consuming web page:-
Is that sort of thing possible?
In fact ideally I'd like to be able to reference SearchCriteria without going via ServiceRefererence 1 or 2 since SearchCriteria doesn't really "belong" to them. Rather I'd like to go via some "Super Reference" that exposed my shared types. Can that be done?
BTW, I'm aware of the "Reuse types in all referenced assemblies" option when adding a service reference. I was expecting that to make ServiceReference2 (which I added second) able to work with shared types that were already exposed via ServiceReference1 but it doesn't seem to do that. I'm a bit mystified as to exactly what it does do to be honest.
E.G.:-
My Shared Type. Defined in a single DataContract.
Code:
[DataContract]
public class SearchCriteria
{
[DataMember]
public string Var1 { get; set; }
[DataMember]
public string Var2 { get; set; }
}
Code:
[ServiceContract]
public interface IService1
{
[OperationContract]
SearchCriteria GetData();
}
Code:
[ServiceContract]
public interface IService2
{
[OperationContract]
SearchCriteria GetData();
}
Code:
public partial class _Default : System.Web.UI.Page
{
private Object memberSearchCriteria; //Wouldn't it be nice if this could be a SearchCriteria rather than an Object?
protected void Page_Load(object sender, EventArgs e)
{
ServiceReference1.Service1Client client1 = new ServiceReference1.Service1Client();
ServiceReference2.Service2Client client2 = new ServiceReference2.Service2Client();
ServiceReference1.SearchCriteria crit1 = client1.GetData();
ServiceReference2.SearchCriteria crit2 = client2.GetData();
memberSearchCriteria = client1.GetData();
memberSearchCriteria = client2.GetData();
//And wouldn't it be nice if I could asign back and forward:-
crit1 = crit2; //Compiler error : Cannot Implicitely Convert...
//Or even explicitely convert:-
crit1 = (ServiceReference1.SearchCriteria)crit2; //Compiler error : Cannot Convert Type...
}
}
In fact ideally I'd like to be able to reference SearchCriteria without going via ServiceRefererence 1 or 2 since SearchCriteria doesn't really "belong" to them. Rather I'd like to go via some "Super Reference" that exposed my shared types. Can that be done?
BTW, I'm aware of the "Reuse types in all referenced assemblies" option when adding a service reference. I was expecting that to make ServiceReference2 (which I added second) able to work with shared types that were already exposed via ServiceReference1 but it doesn't seem to do that. I'm a bit mystified as to exactly what it does do to be honest.