Results 1 to 7 of 7

Thread: [RESOLVED] WCF: Problems creating duplex contract

  1. #1

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Resolved [RESOLVED] WCF: Problems creating duplex contract

    I'm trying to create a duplex contract in my WCF service, which from what I gather requires that you do the following:

    Define an interface in your service, e.g IMyClientCallBack
    Tell your main service to use that interface as its call back contract
    implement the interface in your client

    So I have the following on the server side:

    vb.net Code:
    1. ''' <summary>
    2. ''' Main service
    3. ''' </summary>
    4. <ServiceContract(CallbackContract:=GetType(IProtoChatCallBack), SessionMode:=SessionMode.Required)> _
    5. Public Interface IProtoChatService
    6.  
    7.     <OperationContract()> _
    8.     Function GetServerInfo() As ServerInfoDescription
    9.  
    10.     <OperationContract()> _
    11.     Function GetUserList() As List(Of UserObject)
    12.  
    13.     <OperationContract()> _
    14.     Function SignUserIn(ByVal iUName As String, ByVal iPassword As String) As SignInResult
    15.  
    16.     <OperationContract()> _
    17.     Sub SignUserOut(ByVal iUName As String)
    18.  
    19. End Interface
    20.  
    21. ''' <summary>
    22. ''' Call back contract that will be implemented on client side
    23. ''' </summary>
    24. <ServiceContract()> _
    25. Public Interface IProtoChatCallBack
    26.  
    27.     <OperationContract(IsOneWay:=True)> _
    28.     Sub MessageReceived(ByVal SenderDisplayName As String, ByVal Message As String, ByVal TimeSent As DateTime)
    29.  
    30.     <OperationContract(IsOneWay:=True)> _
    31.     Sub SignUserOut(ByVal Reason As String)
    32.  
    33. End Interface

    However, now when I go to update the service reference on the client (so that I can define an implementation of the call back interface) I just get an error saying "Metadata contains a reference that could not be resolved".
    If I take those 2 methods (MessageReceived and ForceUserSignOut) out of the interface then I can update the service reference on the client fine... but obviously there's not much use having a callback contract that doesnt do anything!

    Anyone see where im going wrong?

    Thanks
    Chris
    Last edited by chris128; Jun 23rd, 2009 at 01:21 PM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: WCF: Problems creating duplex contract

    Set IsOneWay on the IProtoChatService methods that you want to be duplex.

  3. #3

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: WCF: Problems creating duplex contract

    I already have havent I? Look at the second half of that code I posted in the original post

    EDIT: Sorry I thought you said the IProtoChatCallBack methods.
    What you actually said makes even less sense to me though :P None of those methods are 'duplex methods', none of them directly call back to the client. The client calls a method in the contract such as SignUserIn, which then causes the service to add that client to a List(Of IProtoChatCallBack). Then when the server needs to send something out it only tries to send it to the client references it has in this list. Plus if I make them one way then they cant be Functions can they, as the client wont be able to retrieve a value back from the function.
    Last edited by chris128; Jun 23rd, 2009 at 12:23 PM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  4. #4

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: WCF: Problems creating duplex contract

    The even more annoying thing is that I created a new project and just used the example service that the WCF Library template in VS creates for you, and I modified it a tiny bit to add a duplex call back, as shown in the code below, and it works perfectly! I cant see any difference between my code and the example service code..

    vb Code:
    1. <ServiceContract(CallbackContract:=GetType(ICallBk), SessionMode:=SessionMode.Required)> _
    2. Public Interface IService1
    3.  
    4.     <OperationContract()> _
    5.     Function Register() As Boolean
    6.  
    7.     <OperationContract()> _
    8.     Sub PingAll()
    9.  
    10.     ' TODO: Add your service operations here
    11.  
    12. End Interface
    13.  
    14. Public Interface ICallBk
    15.  
    16.     <OperationContract(IsOneWay:=True)> _
    17.     Sub Something(ByVal message As String)
    18.  
    19. End Interface
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: WCF: Problems creating duplex contract

    Well I had given up all hope of solving this in a reasonable and logical way so I resorted to just hacking bits out of my program until it started working and then adding things back in until it stopped working again to see where the problem was. Anyway after spending a long time doing that and getting slightly more confused at some points, I finally found out what the problem is... and in my opinion its something that Visual Studio should have been able to point out very easily instead of giving me a crappy "metadata contains a reference that cannot be resolved" error. The problem was that a method in my callback was named the same as a method in my main service contract (the method is named SignUserOut in the code in my original post). I dont really understand why this cant work as they are two separate interfaces but whatever, it wont, so I renamed the method in the callback and now all works fine. Shame I've wasted a whole day trying to fix the damn thing.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] WCF: Problems creating duplex contract

    Ooh, I should've seen that too. But I didn't, so this proves that I am Visual Studio... It wasn't that obvious though. It might have been an issue because of the serialization that occurs to make the method name available.

    I've once had a similarly unclear error message when I was attempting to get a method to accept and return a custom class. It got confuse as hell in basicHttpBinding because both classes were of the same type.

  7. #7

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [RESOLVED] WCF: Problems creating duplex contract

    Yeah it can be a bit unhelpful with its error messages... apparently VS 2010 should be a bit better with its WCF error messages
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width