|
-
Jun 22nd, 2009, 01:22 PM
#1
[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:
''' <summary>
''' Main service
''' </summary>
<ServiceContract(CallbackContract:=GetType(IProtoChatCallBack), SessionMode:=SessionMode.Required)> _
Public Interface IProtoChatService
<OperationContract()> _
Function GetServerInfo() As ServerInfoDescription
<OperationContract()> _
Function GetUserList() As List(Of UserObject)
<OperationContract()> _
Function SignUserIn(ByVal iUName As String, ByVal iPassword As String) As SignInResult
<OperationContract()> _
Sub SignUserOut(ByVal iUName As String)
End Interface
''' <summary>
''' Call back contract that will be implemented on client side
''' </summary>
<ServiceContract()> _
Public Interface IProtoChatCallBack
<OperationContract(IsOneWay:=True)> _
Sub MessageReceived(ByVal SenderDisplayName As String, ByVal Message As String, ByVal TimeSent As DateTime)
<OperationContract(IsOneWay:=True)> _
Sub SignUserOut(ByVal Reason As String)
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.
-
Jun 23rd, 2009, 12:00 PM
#2
Re: WCF: Problems creating duplex contract
Set IsOneWay on the IProtoChatService methods that you want to be duplex.
-
Jun 23rd, 2009, 12:15 PM
#3
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.
-
Jun 23rd, 2009, 12:27 PM
#4
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:
<ServiceContract(CallbackContract:=GetType(ICallBk), SessionMode:=SessionMode.Required)> _
Public Interface IService1
<OperationContract()> _
Function Register() As Boolean
<OperationContract()> _
Sub PingAll()
' TODO: Add your service operations here
End Interface
Public Interface ICallBk
<OperationContract(IsOneWay:=True)> _
Sub Something(ByVal message As String)
End Interface
-
Jun 23rd, 2009, 01:27 PM
#5
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.
-
Jun 28th, 2009, 02:36 PM
#6
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.
-
Jun 29th, 2009, 03:41 AM
#7
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|