DrAske


Hi Experts ..

I have a generic class ,

class ClassA<K>
{
K id;

DoSomething(..)
{
ClassClient = // Create proxy instance
// Now, call method from client
ClassClient.DoIt(id); <--- The problem is here, id is of type K, and the method parameter is of type long
}
}


so I am getting the compiler error : cannot cast from K to long

I want to have the client to extend an interface with generic type (K), something like this:

class IClientClass<K>
{
DoIt(K id);
}

// THis is the original class
class ClientClass : ClientBase<IClientClass<K>>, IClientClass<K>
{

}

Is that possible could you please help me this is URGENT.



Re: Windows Communication Foundation (Indigo) Proxy problem

BenK

class ClientClass : ClientBase<IClientClass<K>>, IClientClass<K>

why not ClientClass : ClientBase<K>,IClientClass<K>

In most of these cases the bases class implements the interface thoiugh there is nothing stopping a derived class having one.

Regards,

Ben





Re: Windows Communication Foundation (Indigo) Proxy problem

DrAske

Actually K is not reference type, so your solution will generate compile time error.

I tried the following:

[ServiceContract]

public interface IClassA<K>

{

[OperationContract]

string DoIt(K Id);

}

public class ClassA : IClassA<long>

{

public string DoIt(long Id)

{

return "ItWorks!!";

}

}

The generated proxy is :

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]

[System.ServiceModel.ServiceContractAttribute(ConfigurationName="ConsoleApplication3.Client.IClassAOf_Int64")]

public interface IClassAOf_Int64

{

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IClassAOf_Int64/DoIt", ReplyAction="http://tempuri.org/IClassAOf_Int64/DoItResponse")]

string DoIt(long Id);

}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]

public interface IClassAOf_Int64Channel : IClassAOf_K<IClassAOf_Int64>, System.ServiceModel.IClientChannel

{

}

[System.Diagnostics.DebuggerStepThroughAttribute()]

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]

public partial class ClassAOf_Int64Client : System.ServiceModel.ClientBase<IClassAOf_Int64>, IClassAOf_Int64

{

public ClassAOf_Int64Client()

{

}

public ClassAOf_Int64Client(string endpointConfigurationName) :

base(endpointConfigurationName)

{

}

public ClassAOf_Int64Client(string endpointConfigurationName, string remoteAddress) :

base(endpointConfigurationName, remoteAddress)

{

}

public ClassAOf_Int64Client(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :

base(endpointConfigurationName, remoteAddress)

{

}

public ClassAOf_Int64Client(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :

base(binding, remoteAddress)

{

}

public string DoIt(long Id)

{

return base.Channel.DoIt(Id);

}

}

I tried to add interface like this:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]

[System.ServiceModel.ServiceContractAttribute(ConfigurationName = "IClassAOf_K`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]")]

public interface IClassAOf_K<K>

{

[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IClassAOf_K`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]/DoIt",

ReplyAction = "http://tempuri.org/IClassAOf_K`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]/DoItResponse")]

string DoIt(K Id);

}

and have the client to extend this interface, then when I run the code I got the following exception:

The message with Action 'http://tempuri.org/IClassAOf_K`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]/DoIt' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

so I replaced the action of the method to make it similar to the method generated in IClassAOf_Int64, and it works!!

What do you think





Re: Windows Communication Foundation (Indigo) Proxy problem

BenK

So you eended up using action http://tempuri.org/IClassAOf_Int64/DoIt

instead of http://tempuri.org/IClassAOf_Int64/DoIt'1

This stuff is so tied up into the guts of WCF you really need reflector to see whats going on and there is no guarantee it will work in later version .

The only thing guaranteed is the xml and all the type extensions are just fluff which other systems will make no sense of. Personally i always copy complex business structures ( eg anything with inheritance , interfaces or generics) to simple message objects which redpresend the messages . No complexity , my business layer is clean ( ie not compromised by the data ) and the message layer can be optomised to minimise traffic / frequent messages.

Regards,

Ben





Re: Windows Communication Foundation (Indigo) Proxy problem

DrAske

Thanx ben Surprise) I solved the problem by replaing the interface I added


[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]

[System.ServiceModel.ServiceContractAttribute(ConfigurationName = "IClassAOf_K`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]")]

public interface IClassAOf_K<K>

{

[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IClassAOf_K`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]/DoIt",

ReplyAction = "http://tempuri.org/IClassAOf_K`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]/DoItResponse")]

string DoIt(K Id);

}


with one without the attributes and it works fine Surprise)


public interface IClassAOf_K<K>

{

string DoIt(K Id);

}



thank you for your help,

really appreciate your time Surprise)