Windows Vista Forums

Limitation in WCF: ineritance of generic interfaces
  1. #1


    Mike Scott Guest

    Limitation in WCF: ineritance of generic interfaces

    I seem to have found a limitation in WCF when using generic interfaces. For
    example:



    [ServiceContract]
    public interface IGeneric<T>
    {
    [OperationContract]
    T Get();
    }

    [ServiceContract]
    public interface IAggregate : IGeneric<int>, IGeneric<string>
    {
    }

    Trying to use IAggregate fails because there are two Get() methods, one
    which takes an int and one which takes a string. WCF's exception message
    helpfully suggests adding a Name="xxx" parameter to the OperationContract.
    However, since the Get() method is defined in IGeneric<T>, it's not possible
    to put separate Name="xxx" parameters of the closed generic methods.

    Comments?

    MikeS.


      My System SpecsSystem Spec

  2. #2


    Arkady Frenkel Guest

    Re: Limitation in WCF: ineritance of generic interfaces

    WCF doesn't not support open generic types , so the only way to use
    [ServiceContract]
    public interface ISomeInterface<SomeConcreteType>
    {
    [OperationContract]
    T Get();
    }

    Arkady

    "Mike Scott" <someone@microsoft.com> wrote in message
    news:et7Crm0AHHA.4808@TK2MSFTNGP03.phx.gbl...
    >I seem to have found a limitation in WCF when using generic interfaces. For
    >example:
    >
    > [ServiceContract]
    > public interface IGeneric<T>
    > {
    > [OperationContract]
    > T Get();
    > }
    >
    > [ServiceContract]
    > public interface IAggregate : IGeneric<int>, IGeneric<string>
    > {
    > }
    >
    > Trying to use IAggregate fails because there are two Get() methods, one
    > which takes an int and one which takes a string. WCF's exception message
    > helpfully suggests adding a Name="xxx" parameter to the OperationContract.
    > However, since the Get() method is defined in IGeneric<T>, it's not
    > possible to put separate Name="xxx" parameters of the closed generic
    > methods.
    >
    > Comments?
    >
    > MikeS.
    >



      My System SpecsSystem Spec

  3. #3


    Mike Scott Guest

    Re: Limitation in WCF: ineritance of generic interfaces

    Hi again

    I know that WCF doesn't support open generic types. But my example uses
    closed generic types, i.e. IGeneric<int> and IGeneric<string>. This is not
    the problem.

    The problem is not being able to differentiate the names of two closed
    generic methods resulting in deriving an interface from a generic interface.
    The following is closed:

    [ServiceContract]
    public interface IAggregate : IGeneric<int>, IGeneric<string>
    {
    }

    It has two methods called Get(), one that takes an int and the other a
    string. They will be named GetOf_Int32 and GetOf_String by the runtime. But
    I can't see a way to "get at" these methods so that they can have a Name
    assigned. For example, if they were overloads you could do this:

    [ServiceContract]
    public interface IAggregate
    {
    [OperationContract(Name="GetByInt")]
    int Get( int value );

    [OperationContract(Name="GetByString")]
    int Get( string value );
    }

    Unfortunately, the serializer doesn't seem to be aware of the fact that it's
    possible to derive an interface multiple times from different closed
    "versions" of a single generic interface. If it did, it could differentiate
    the names itself.

    MikeS.


    "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    news:%23UsziD1AHHA.4592@TK2MSFTNGP03.phx.gbl...
    > WCF doesn't not support open generic types , so the only way to use
    > [ServiceContract]
    > public interface ISomeInterface<SomeConcreteType>
    > {
    > [OperationContract]
    > T Get();
    > }
    >
    > Arkady
    >
    > "Mike Scott" <someone@microsoft.com> wrote in message
    > news:et7Crm0AHHA.4808@TK2MSFTNGP03.phx.gbl...
    >>I seem to have found a limitation in WCF when using generic interfaces.
    >>For example:
    >>
    >> [ServiceContract]
    >> public interface IGeneric<T>
    >> {
    >> [OperationContract]
    >> T Get();
    >> }
    >>
    >> [ServiceContract]
    >> public interface IAggregate : IGeneric<int>, IGeneric<string>
    >> {
    >> }
    >>
    >> Trying to use IAggregate fails because there are two Get() methods, one
    >> which takes an int and one which takes a string. WCF's exception message
    >> helpfully suggests adding a Name="xxx" parameter to the
    >> OperationContract. However, since the Get() method is defined in
    >> IGeneric<T>, it's not possible to put separate Name="xxx" parameters of
    >> the closed generic methods.
    >>
    >> Comments?
    >>
    >> MikeS.
    >>

    >
    >



      My System SpecsSystem Spec

  4. #4


    Arkady Frenkel Guest

    Re: Limitation in WCF: ineritance of generic interfaces

    Hi!
    What I mean that you can't use next because it still open type

    [ServiceContract]
    public interface IGeneric<T>
    {
    [OperationContract]
    T Get();
    }



    Arkady


    "Mike Scott" <someone@microsoft.com> wrote in message
    news:Oypf$H2AHHA.4680@TK2MSFTNGP04.phx.gbl...
    > Hi again
    >
    > I know that WCF doesn't support open generic types. But my example uses
    > closed generic types, i.e. IGeneric<int> and IGeneric<string>. This is not
    > the problem.
    >
    > The problem is not being able to differentiate the names of two closed
    > generic methods resulting in deriving an interface from a generic
    > interface. The following is closed:
    >
    > [ServiceContract]
    > public interface IAggregate : IGeneric<int>, IGeneric<string>
    > {
    > }
    >
    > It has two methods called Get(), one that takes an int and the other a
    > string. They will be named GetOf_Int32 and GetOf_String by the runtime.
    > But I can't see a way to "get at" these methods so that they can have a
    > Name assigned. For example, if they were overloads you could do this:
    >
    > [ServiceContract]
    > public interface IAggregate
    > {
    > [OperationContract(Name="GetByInt")]
    > int Get( int value );
    >
    > [OperationContract(Name="GetByString")]
    > int Get( string value );
    > }
    >
    > Unfortunately, the serializer doesn't seem to be aware of the fact that
    > it's possible to derive an interface multiple times from different closed
    > "versions" of a single generic interface. If it did, it could
    > differentiate the names itself.
    >
    > MikeS.
    >
    >
    > "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    > news:%23UsziD1AHHA.4592@TK2MSFTNGP03.phx.gbl...
    >> WCF doesn't not support open generic types , so the only way to use
    >> [ServiceContract]
    >> public interface ISomeInterface<SomeConcreteType>
    >> {
    >> [OperationContract]
    >> T Get();
    >> }
    >>
    >> Arkady
    >>
    >> "Mike Scott" <someone@microsoft.com> wrote in message
    >> news:et7Crm0AHHA.4808@TK2MSFTNGP03.phx.gbl...
    >>>I seem to have found a limitation in WCF when using generic interfaces.
    >>>For example:
    >>>
    >>> [ServiceContract]
    >>> public interface IGeneric<T>
    >>> {
    >>> [OperationContract]
    >>> T Get();
    >>> }
    >>>
    >>> [ServiceContract]
    >>> public interface IAggregate : IGeneric<int>, IGeneric<string>
    >>> {
    >>> }
    >>>
    >>> Trying to use IAggregate fails because there are two Get() methods, one
    >>> which takes an int and one which takes a string. WCF's exception message
    >>> helpfully suggests adding a Name="xxx" parameter to the
    >>> OperationContract. However, since the Get() method is defined in
    >>> IGeneric<T>, it's not possible to put separate Name="xxx" parameters of
    >>> the closed generic methods.
    >>>
    >>> Comments?
    >>>
    >>> MikeS.
    >>>

    >>
    >>

    >
    >



      My System SpecsSystem Spec

  5. #5


    Arkady Frenkel Guest

    Re: Limitation in WCF: ineritance of generic interfaces

    Additionally , that limitation of SOA in all , if you put two( few ) methods
    with the same name in the service. Look at
    http://www-128.ibm.com/developerworks/library/ws-peer2/

    a.. Methods: A white-space delimited list of the methods to expose in the
    Web service. Note that this seems to imply that a Web service cannot expose
    two methods with the same name, but there is nothing in the SOAP
    specification that prevents this.

    In WCF when you Trace the message flow you'll see <ActivityName> - name of
    method to execute as "....Interface.Method." so when it come yet no data
    arrive to check which ( from set ) method to call

    Arkady


    "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    news:OUUxfz2AHHA.3928@TK2MSFTNGP03.phx.gbl...
    > Hi!
    > What I mean that you can't use next because it still open type
    >
    > [ServiceContract]
    > public interface IGeneric<T>
    > {
    > [OperationContract]
    > T Get();
    > }
    >
    >
    >
    > Arkady
    >
    >
    > "Mike Scott" <someone@microsoft.com> wrote in message
    > news:Oypf$H2AHHA.4680@TK2MSFTNGP04.phx.gbl...
    >> Hi again
    >>
    >> I know that WCF doesn't support open generic types. But my example uses
    >> closed generic types, i.e. IGeneric<int> and IGeneric<string>. This is
    >> not the problem.
    >>
    >> The problem is not being able to differentiate the names of two closed
    >> generic methods resulting in deriving an interface from a generic
    >> interface. The following is closed:
    >>
    >> [ServiceContract]
    >> public interface IAggregate : IGeneric<int>, IGeneric<string>
    >> {
    >> }
    >>
    >> It has two methods called Get(), one that takes an int and the other a
    >> string. They will be named GetOf_Int32 and GetOf_String by the runtime.
    >> But I can't see a way to "get at" these methods so that they can have a
    >> Name assigned. For example, if they were overloads you could do this:
    >>
    >> [ServiceContract]
    >> public interface IAggregate
    >> {
    >> [OperationContract(Name="GetByInt")]
    >> int Get( int value );
    >>
    >> [OperationContract(Name="GetByString")]
    >> int Get( string value );
    >> }
    >>
    >> Unfortunately, the serializer doesn't seem to be aware of the fact that
    >> it's possible to derive an interface multiple times from different closed
    >> "versions" of a single generic interface. If it did, it could
    >> differentiate the names itself.
    >>
    >> MikeS.
    >>
    >>
    >> "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    >> news:%23UsziD1AHHA.4592@TK2MSFTNGP03.phx.gbl...
    >>> WCF doesn't not support open generic types , so the only way to use
    >>> [ServiceContract]
    >>> public interface ISomeInterface<SomeConcreteType>
    >>> {
    >>> [OperationContract]
    >>> T Get();
    >>> }
    >>>
    >>> Arkady
    >>>
    >>> "Mike Scott" <someone@microsoft.com> wrote in message
    >>> news:et7Crm0AHHA.4808@TK2MSFTNGP03.phx.gbl...
    >>>>I seem to have found a limitation in WCF when using generic interfaces.
    >>>>For example:
    >>>>
    >>>> [ServiceContract]
    >>>> public interface IGeneric<T>
    >>>> {
    >>>> [OperationContract]
    >>>> T Get();
    >>>> }
    >>>>
    >>>> [ServiceContract]
    >>>> public interface IAggregate : IGeneric<int>, IGeneric<string>
    >>>> {
    >>>> }
    >>>>
    >>>> Trying to use IAggregate fails because there are two Get() methods, one
    >>>> which takes an int and one which takes a string. WCF's exception
    >>>> message helpfully suggests adding a Name="xxx" parameter to the
    >>>> OperationContract. However, since the Get() method is defined in
    >>>> IGeneric<T>, it's not possible to put separate Name="xxx" parameters of
    >>>> the closed generic methods.
    >>>>
    >>>> Comments?
    >>>>
    >>>> MikeS.
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >



      My System SpecsSystem Spec

  6. #6


    Mike Scott Guest

    Re: Limitation in WCF: ineritance of generic interfaces

    I don't think what you're saying is correct. This works fine:

    [ServiceContract]
    public interface IAggregate : IGeneric<int>
    {
    }

    IOW, it's not the "generic-ness" of the interfaces that's the problem. It's
    the fact, as I've explained, that when IAggregate derives twice from the
    IGeneric interface that there's a problem at runtime, simply because there's
    no way to adorn the specific Get() methods with unique names.

    Cheers,

    Mike.

    "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    news:OUUxfz2AHHA.3928@TK2MSFTNGP03.phx.gbl...
    > Hi!
    > What I mean that you can't use next because it still open type
    >
    > [ServiceContract]
    > public interface IGeneric<T>
    > {
    > [OperationContract]
    > T Get();
    > }
    >
    >
    >
    > Arkady
    >
    >
    > "Mike Scott" <someone@microsoft.com> wrote in message
    > news:Oypf$H2AHHA.4680@TK2MSFTNGP04.phx.gbl...
    >> Hi again
    >>
    >> I know that WCF doesn't support open generic types. But my example uses
    >> closed generic types, i.e. IGeneric<int> and IGeneric<string>. This is
    >> not the problem.
    >>
    >> The problem is not being able to differentiate the names of two closed
    >> generic methods resulting in deriving an interface from a generic
    >> interface. The following is closed:
    >>
    >> [ServiceContract]
    >> public interface IAggregate : IGeneric<int>, IGeneric<string>
    >> {
    >> }
    >>
    >> It has two methods called Get(), one that takes an int and the other a
    >> string. They will be named GetOf_Int32 and GetOf_String by the runtime.
    >> But I can't see a way to "get at" these methods so that they can have a
    >> Name assigned. For example, if they were overloads you could do this:
    >>
    >> [ServiceContract]
    >> public interface IAggregate
    >> {
    >> [OperationContract(Name="GetByInt")]
    >> int Get( int value );
    >>
    >> [OperationContract(Name="GetByString")]
    >> int Get( string value );
    >> }
    >>
    >> Unfortunately, the serializer doesn't seem to be aware of the fact that
    >> it's possible to derive an interface multiple times from different closed
    >> "versions" of a single generic interface. If it did, it could
    >> differentiate the names itself.
    >>
    >> MikeS.
    >>
    >>
    >> "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    >> news:%23UsziD1AHHA.4592@TK2MSFTNGP03.phx.gbl...
    >>> WCF doesn't not support open generic types , so the only way to use
    >>> [ServiceContract]
    >>> public interface ISomeInterface<SomeConcreteType>
    >>> {
    >>> [OperationContract]
    >>> T Get();
    >>> }
    >>>
    >>> Arkady
    >>>
    >>> "Mike Scott" <someone@microsoft.com> wrote in message
    >>> news:et7Crm0AHHA.4808@TK2MSFTNGP03.phx.gbl...
    >>>>I seem to have found a limitation in WCF when using generic interfaces.
    >>>>For example:
    >>>>
    >>>> [ServiceContract]
    >>>> public interface IGeneric<T>
    >>>> {
    >>>> [OperationContract]
    >>>> T Get();
    >>>> }
    >>>>
    >>>> [ServiceContract]
    >>>> public interface IAggregate : IGeneric<int>, IGeneric<string>
    >>>> {
    >>>> }
    >>>>
    >>>> Trying to use IAggregate fails because there are two Get() methods, one
    >>>> which takes an int and one which takes a string. WCF's exception
    >>>> message helpfully suggests adding a Name="xxx" parameter to the
    >>>> OperationContract. However, since the Get() method is defined in
    >>>> IGeneric<T>, it's not possible to put separate Name="xxx" parameters of
    >>>> the closed generic methods.
    >>>>
    >>>> Comments?
    >>>>
    >>>> MikeS.
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >



      My System SpecsSystem Spec

  7. #7


    Mike Scott Guest

    Re: Limitation in WCF: ineritance of generic interfaces

    Hi

    Having two methods with the same name isn't a problem. Look at this:

    [ServiceContract]
    public interface IFoo
    {
    [OperationContract]
    void Do();
    }

    [ServiceContract]
    public interface IBar
    {
    [OperationContract]
    void Do();
    }

    [ServiceContract]
    public interface IFooBar : IFoo, IBar
    {
    }

    If you try to use IFooBar over WCF the formatter will complain because there
    are two Do() methods. The solution is to use the OperationContract attribute
    to give them unique names. So this works:

    [ServiceContract]
    public interface IFoo
    {
    [OperationContract(Name="IFoo.Do"]
    void Do();
    }

    [ServiceContract]
    public interface IBar
    {
    [OperationContract(Name="IBar.Do"]
    void Do();
    }

    [ServiceContract]
    public interface IFooBar : IFoo, IBar
    {
    }

    Like I say, the above works perfectly with WCF. But with the *generic* case
    which I showed earlier in the thread, there's no way to specify different
    names for the methods defined in the generic interface when you use the same
    generic interface more than once as a parent of the derived interface.

    It's nothing to do with the fact that the interfaces are generic, but that
    there's no way to tell the formatter to use different names for the
    different closed instances of the methods.

    Cheers,

    MikeS.

    "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    news:%23PvFTU9AHHA.1196@TK2MSFTNGP03.phx.gbl...
    > Additionally , that limitation of SOA in all , if you put two( few )
    > methods with the same name in the service. Look at
    > http://www-128.ibm.com/developerworks/library/ws-peer2/
    >
    > a.. Methods: A white-space delimited list of the methods to expose in the
    > Web service. Note that this seems to imply that a Web service cannot
    > expose two methods with the same name, but there is nothing in the SOAP
    > specification that prevents this.
    >
    > In WCF when you Trace the message flow you'll see <ActivityName> - name of
    > method to execute as "....Interface.Method." so when it come yet no data
    > arrive to check which ( from set ) method to call
    >
    > Arkady
    >
    >
    > "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    > news:OUUxfz2AHHA.3928@TK2MSFTNGP03.phx.gbl...
    >> Hi!
    >> What I mean that you can't use next because it still open type
    >>
    >> [ServiceContract]
    >> public interface IGeneric<T>
    >> {
    >> [OperationContract]
    >> T Get();
    >> }
    >>
    >>
    >>
    >> Arkady
    >>
    >>
    >> "Mike Scott" <someone@microsoft.com> wrote in message
    >> news:Oypf$H2AHHA.4680@TK2MSFTNGP04.phx.gbl...
    >>> Hi again
    >>>
    >>> I know that WCF doesn't support open generic types. But my example uses
    >>> closed generic types, i.e. IGeneric<int> and IGeneric<string>. This is
    >>> not the problem.
    >>>
    >>> The problem is not being able to differentiate the names of two closed
    >>> generic methods resulting in deriving an interface from a generic
    >>> interface. The following is closed:
    >>>
    >>> [ServiceContract]
    >>> public interface IAggregate : IGeneric<int>, IGeneric<string>
    >>> {
    >>> }
    >>>
    >>> It has two methods called Get(), one that takes an int and the other a
    >>> string. They will be named GetOf_Int32 and GetOf_String by the runtime.
    >>> But I can't see a way to "get at" these methods so that they can have a
    >>> Name assigned. For example, if they were overloads you could do this:
    >>>
    >>> [ServiceContract]
    >>> public interface IAggregate
    >>> {
    >>> [OperationContract(Name="GetByInt")]
    >>> int Get( int value );
    >>>
    >>> [OperationContract(Name="GetByString")]
    >>> int Get( string value );
    >>> }
    >>>
    >>> Unfortunately, the serializer doesn't seem to be aware of the fact that
    >>> it's possible to derive an interface multiple times from different
    >>> closed "versions" of a single generic interface. If it did, it could
    >>> differentiate the names itself.
    >>>
    >>> MikeS.
    >>>
    >>>
    >>> "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    >>> news:%23UsziD1AHHA.4592@TK2MSFTNGP03.phx.gbl...
    >>>> WCF doesn't not support open generic types , so the only way to use
    >>>> [ServiceContract]
    >>>> public interface ISomeInterface<SomeConcreteType>
    >>>> {
    >>>> [OperationContract]
    >>>> T Get();
    >>>> }
    >>>>
    >>>> Arkady
    >>>>
    >>>> "Mike Scott" <someone@microsoft.com> wrote in message
    >>>> news:et7Crm0AHHA.4808@TK2MSFTNGP03.phx.gbl...
    >>>>>I seem to have found a limitation in WCF when using generic interfaces.
    >>>>>For example:
    >>>>>
    >>>>> [ServiceContract]
    >>>>> public interface IGeneric<T>
    >>>>> {
    >>>>> [OperationContract]
    >>>>> T Get();
    >>>>> }
    >>>>>
    >>>>> [ServiceContract]
    >>>>> public interface IAggregate : IGeneric<int>, IGeneric<string>
    >>>>> {
    >>>>> }
    >>>>>
    >>>>> Trying to use IAggregate fails because there are two Get() methods,
    >>>>> one which takes an int and one which takes a string. WCF's exception
    >>>>> message helpfully suggests adding a Name="xxx" parameter to the
    >>>>> OperationContract. However, since the Get() method is defined in
    >>>>> IGeneric<T>, it's not possible to put separate Name="xxx" parameters
    >>>>> of the closed generic methods.
    >>>>>
    >>>>> Comments?
    >>>>>
    >>>>> MikeS.
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >



      My System SpecsSystem Spec

  8. #8


    Arkady Frenkel Guest

    Re: Limitation in WCF: ineritance of generic interfaces

    You show using with close type - int and I wrote open type - T
    Arkady

    "Mike Scott" <someone@microsoft.com> wrote in message
    news:uOIQJyCBHHA.5060@TK2MSFTNGP02.phx.gbl...
    >I don't think what you're saying is correct. This works fine:
    >
    > [ServiceContract]
    > public interface IAggregate : IGeneric<int>
    > {
    > }
    >
    > IOW, it's not the "generic-ness" of the interfaces that's the problem.
    > It's the fact, as I've explained, that when IAggregate derives twice from
    > the IGeneric interface that there's a problem at runtime, simply because
    > there's no way to adorn the specific Get() methods with unique names.
    >
    > Cheers,
    >
    > Mike.
    >
    > "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    > news:OUUxfz2AHHA.3928@TK2MSFTNGP03.phx.gbl...
    >> Hi!
    >> What I mean that you can't use next because it still open type
    >>
    >> [ServiceContract]
    >> public interface IGeneric<T>
    >> {
    >> [OperationContract]
    >> T Get();
    >> }
    >>
    >>
    >>
    >> Arkady
    >>
    >>
    >> "Mike Scott" <someone@microsoft.com> wrote in message
    >> news:Oypf$H2AHHA.4680@TK2MSFTNGP04.phx.gbl...
    >>> Hi again
    >>>
    >>> I know that WCF doesn't support open generic types. But my example uses
    >>> closed generic types, i.e. IGeneric<int> and IGeneric<string>. This is
    >>> not the problem.
    >>>
    >>> The problem is not being able to differentiate the names of two closed
    >>> generic methods resulting in deriving an interface from a generic
    >>> interface. The following is closed:
    >>>
    >>> [ServiceContract]
    >>> public interface IAggregate : IGeneric<int>, IGeneric<string>
    >>> {
    >>> }
    >>>
    >>> It has two methods called Get(), one that takes an int and the other a
    >>> string. They will be named GetOf_Int32 and GetOf_String by the runtime.
    >>> But I can't see a way to "get at" these methods so that they can have a
    >>> Name assigned. For example, if they were overloads you could do this:
    >>>
    >>> [ServiceContract]
    >>> public interface IAggregate
    >>> {
    >>> [OperationContract(Name="GetByInt")]
    >>> int Get( int value );
    >>>
    >>> [OperationContract(Name="GetByString")]
    >>> int Get( string value );
    >>> }
    >>>
    >>> Unfortunately, the serializer doesn't seem to be aware of the fact that
    >>> it's possible to derive an interface multiple times from different
    >>> closed "versions" of a single generic interface. If it did, it could
    >>> differentiate the names itself.
    >>>
    >>> MikeS.
    >>>
    >>>
    >>> "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    >>> news:%23UsziD1AHHA.4592@TK2MSFTNGP03.phx.gbl...
    >>>> WCF doesn't not support open generic types , so the only way to use
    >>>> [ServiceContract]
    >>>> public interface ISomeInterface<SomeConcreteType>
    >>>> {
    >>>> [OperationContract]
    >>>> T Get();
    >>>> }
    >>>>
    >>>> Arkady
    >>>>
    >>>> "Mike Scott" <someone@microsoft.com> wrote in message
    >>>> news:et7Crm0AHHA.4808@TK2MSFTNGP03.phx.gbl...
    >>>>>I seem to have found a limitation in WCF when using generic interfaces.
    >>>>>For example:
    >>>>>
    >>>>> [ServiceContract]
    >>>>> public interface IGeneric<T>
    >>>>> {
    >>>>> [OperationContract]
    >>>>> T Get();
    >>>>> }
    >>>>>
    >>>>> [ServiceContract]
    >>>>> public interface IAggregate : IGeneric<int>, IGeneric<string>
    >>>>> {
    >>>>> }
    >>>>>
    >>>>> Trying to use IAggregate fails because there are two Get() methods,
    >>>>> one which takes an int and one which takes a string. WCF's exception
    >>>>> message helpfully suggests adding a Name="xxx" parameter to the
    >>>>> OperationContract. However, since the Get() method is defined in
    >>>>> IGeneric<T>, it's not possible to put separate Name="xxx" parameters
    >>>>> of the closed generic methods.
    >>>>>
    >>>>> Comments?
    >>>>>
    >>>>> MikeS.
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >



      My System SpecsSystem Spec

  9. #9


    Arkady Frenkel Guest

    Re: Limitation in WCF: ineritance of generic interfaces

    That work because you open type still in use and that not allow to change
    name as you did with Name attribute
    Arkady

    "Mike Scott" <someone@microsoft.com> wrote in message
    news:etIB21CBHHA.2328@TK2MSFTNGP02.phx.gbl...
    > Hi
    >
    > Having two methods with the same name isn't a problem. Look at this:
    >
    > [ServiceContract]
    > public interface IFoo
    > {
    > [OperationContract]
    > void Do();
    > }
    >
    > [ServiceContract]
    > public interface IBar
    > {
    > [OperationContract]
    > void Do();
    > }
    >
    > [ServiceContract]
    > public interface IFooBar : IFoo, IBar
    > {
    > }
    >
    > If you try to use IFooBar over WCF the formatter will complain because
    > there are two Do() methods. The solution is to use the OperationContract
    > attribute to give them unique names. So this works:
    >
    > [ServiceContract]
    > public interface IFoo
    > {
    > [OperationContract(Name="IFoo.Do"]
    > void Do();
    > }
    >
    > [ServiceContract]
    > public interface IBar
    > {
    > [OperationContract(Name="IBar.Do"]
    > void Do();
    > }
    >
    > [ServiceContract]
    > public interface IFooBar : IFoo, IBar
    > {
    > }
    >
    > Like I say, the above works perfectly with WCF. But with the *generic*
    > case which I showed earlier in the thread, there's no way to specify
    > different names for the methods defined in the generic interface when you
    > use the same generic interface more than once as a parent of the derived
    > interface.
    >
    > It's nothing to do with the fact that the interfaces are generic, but that
    > there's no way to tell the formatter to use different names for the
    > different closed instances of the methods.
    >
    > Cheers,
    >
    > MikeS.
    >
    > "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    > news:%23PvFTU9AHHA.1196@TK2MSFTNGP03.phx.gbl...
    >> Additionally , that limitation of SOA in all , if you put two( few )
    >> methods with the same name in the service. Look at
    >> http://www-128.ibm.com/developerworks/library/ws-peer2/
    >>
    >> a.. Methods: A white-space delimited list of the methods to expose in the
    >> Web service. Note that this seems to imply that a Web service cannot
    >> expose two methods with the same name, but there is nothing in the SOAP
    >> specification that prevents this.
    >>
    >> In WCF when you Trace the message flow you'll see <ActivityName> - name
    >> of method to execute as "....Interface.Method." so when it come yet no
    >> data arrive to check which ( from set ) method to call
    >>
    >> Arkady
    >>
    >>
    >> "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    >> news:OUUxfz2AHHA.3928@TK2MSFTNGP03.phx.gbl...
    >>> Hi!
    >>> What I mean that you can't use next because it still open type
    >>>
    >>> [ServiceContract]
    >>> public interface IGeneric<T>
    >>> {
    >>> [OperationContract]
    >>> T Get();
    >>> }
    >>>
    >>>
    >>>
    >>> Arkady
    >>>
    >>>
    >>> "Mike Scott" <someone@microsoft.com> wrote in message
    >>> news:Oypf$H2AHHA.4680@TK2MSFTNGP04.phx.gbl...
    >>>> Hi again
    >>>>
    >>>> I know that WCF doesn't support open generic types. But my example uses
    >>>> closed generic types, i.e. IGeneric<int> and IGeneric<string>. This is
    >>>> not the problem.
    >>>>
    >>>> The problem is not being able to differentiate the names of two closed
    >>>> generic methods resulting in deriving an interface from a generic
    >>>> interface. The following is closed:
    >>>>
    >>>> [ServiceContract]
    >>>> public interface IAggregate : IGeneric<int>, IGeneric<string>
    >>>> {
    >>>> }
    >>>>
    >>>> It has two methods called Get(), one that takes an int and the other a
    >>>> string. They will be named GetOf_Int32 and GetOf_String by the runtime.
    >>>> But I can't see a way to "get at" these methods so that they can have a
    >>>> Name assigned. For example, if they were overloads you could do this:
    >>>>
    >>>> [ServiceContract]
    >>>> public interface IAggregate
    >>>> {
    >>>> [OperationContract(Name="GetByInt")]
    >>>> int Get( int value );
    >>>>
    >>>> [OperationContract(Name="GetByString")]
    >>>> int Get( string value );
    >>>> }
    >>>>
    >>>> Unfortunately, the serializer doesn't seem to be aware of the fact that
    >>>> it's possible to derive an interface multiple times from different
    >>>> closed "versions" of a single generic interface. If it did, it could
    >>>> differentiate the names itself.
    >>>>
    >>>> MikeS.
    >>>>
    >>>>
    >>>> "Arkady Frenkel" <arkadyf@hotmailxdotx.com> wrote in message
    >>>> news:%23UsziD1AHHA.4592@TK2MSFTNGP03.phx.gbl...
    >>>>> WCF doesn't not support open generic types , so the only way to use
    >>>>> [ServiceContract]
    >>>>> public interface ISomeInterface<SomeConcreteType>
    >>>>> {
    >>>>> [OperationContract]
    >>>>> T Get();
    >>>>> }
    >>>>>
    >>>>> Arkady
    >>>>>
    >>>>> "Mike Scott" <someone@microsoft.com> wrote in message
    >>>>> news:et7Crm0AHHA.4808@TK2MSFTNGP03.phx.gbl...
    >>>>>>I seem to have found a limitation in WCF when using generic
    >>>>>>interfaces. For example:
    >>>>>>
    >>>>>> [ServiceContract]
    >>>>>> public interface IGeneric<T>
    >>>>>> {
    >>>>>> [OperationContract]
    >>>>>> T Get();
    >>>>>> }
    >>>>>>
    >>>>>> [ServiceContract]
    >>>>>> public interface IAggregate : IGeneric<int>, IGeneric<string>
    >>>>>> {
    >>>>>> }
    >>>>>>
    >>>>>> Trying to use IAggregate fails because there are two Get() methods,
    >>>>>> one which takes an int and one which takes a string. WCF's exception
    >>>>>> message helpfully suggests adding a Name="xxx" parameter to the
    >>>>>> OperationContract. However, since the Get() method is defined in
    >>>>>> IGeneric<T>, it's not possible to put separate Name="xxx" parameters
    >>>>>> of the closed generic methods.
    >>>>>>
    >>>>>> Comments?
    >>>>>>
    >>>>>> MikeS.
    >>>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >



      My System SpecsSystem Spec

  10. #10


    Sara Wong [MS] Guest

    RE: Limitation in WCF: ineritance of generic interfaces

    Mike,

    This is a known limiation. You can work around it by using the
    [ServiceContract] attributes on the class where you implements all the closed
    generic method. You can then specify names like below:

    public interface IGeneric<T>
    {
    T Get();
    }

    [ServiceContract]
    public class Aggregates : IGeneric<int>, I Generic<string>
    {
    [OperationContract(Name="GetInt")]
    public int Get() { return ...}

    [OperationContract(Name="GetString")]
    public string() { return ...}

    }

    Hope this helps.

    Thanks,
    Sara



    "Mike Scott" wrote:

    > I seem to have found a limitation in WCF when using generic interfaces. For
    > example:
    >
    > [ServiceContract]
    > public interface IGeneric<T>
    > {
    > [OperationContract]
    > T Get();
    > }
    >
    > [ServiceContract]
    > public interface IAggregate : IGeneric<int>, IGeneric<string>
    > {
    > }
    >
    > Trying to use IAggregate fails because there are two Get() methods, one
    > which takes an int and one which takes a string. WCF's exception message
    > helpfully suggests adding a Name="xxx" parameter to the OperationContract.
    > However, since the Get() method is defined in IGeneric<T>, it's not possible
    > to put separate Name="xxx" parameters of the closed generic methods.
    >
    > Comments?
    >
    > MikeS.
    >
    >
    >

      My System SpecsSystem Spec

Limitation in WCF: ineritance of generic interfaces problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Video Capture Interfaces jordao VB Script 1 21 Sep 2009
Bridge network interfaces? just bob Vista networking & sharing 1 05 Apr 2008
I knew it..Pretty Interfaces are just slow Dale White Vista General 51 25 Mar 2007
switching between Basic & Aero interfaces foreverLaur Vista account administration 1 03 Feb 2007
Using Interfaces chris-at PowerShell 3 04 Jan 2007