Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,

I am working on a service for silverlight. The operation contract is defined like this :
MIDL
[ServiceContract]
    public interface IFeedbackAppProxy
    {
        [OperationContract]
        void InsertQuestions(IEnumerable<Question> questions, Action<int> callback);
        [OperationContract]
        void InsertQuestion(Question questions, Action<int> callback);
        [OperationContract]
        void InsertAnswer(MultipleChoiceAnswer answer, Action<int> callback);
        [OperationContract]
        void InsertAnswers(IEnumerable<MultipleChoiceAnswer> answer, Action<int> callback);
        [OperationContract]
        void InsertTag(Tag tag, Action<int> callback);
        [OperationContract]
        void InsertTagXQuestion(Tag tag, int questionID, Action<int> callback);
        [OperationContract]
        void InsertTags(IEnumerable<Tag> tag, Action<int> callback);
        [OperationContract]
        void InsertTagsXQuestion(IEnumerable<Tag> tag, int questionID, Action<int> callback);
    }



I also have a test project with reference to the service and the folowing dummy test method :
C#
[TestMethod]
       public void TestMethod1()
       {
           FeedbackAppProxyClient myFeedbackApp = new FeedbackAppProxyClient();
           myFeedbackApp.Open();
           myFeedbackApp.InsertQuestion(new Question(), i => { });
       }


When I debug the test method, I get :

There was an error while trying to serialize parameter http://tempuri.org/:callback. The InnerException message was 'Type 'System.DelegateSerializationHolder+DelegateEntry' with data contract name 'DelegateSerializationHolder.DelegateEntry:http://schemas.datacontract.org/2004/07/System' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.

What should I do ?

Thank you,
Bogdan
Posted

1 solution

What you might want to do is to use the callback system that is available in WCF Services. Since your callbacks can be on a different machine and not just locally, I think you would have a problem just putting the action in that way you had. You could setup something like this...

C#
[ServiceContract(Name = "FeedbackService",
    Namespace = "http://mycompany.com/FeedbackServices",
    CallbackContract = typeof(IFeedbackAppProxyCallback),
    SessionMode = SessionMode.Required)]
public interface IFeedbackAppProxy
{
    [OperationContract]
    void Subscribe();

    [OperationContract]
    void Unsubscribe();
}


C#
public interface IFeedbackAppProxyCallback
{
    [OperationContract(IsOneWay = true)]
    void QuestionAnswered(Question q, Answer a);
}


Then in the implementation of the service for the subscribing you can add this...

C#
IFeedbackAppProxyCallback callback;

public void Subscribe()
{
    callback = OperationContext.Current.GetCallbackChannel<IFeedbackAppProxyCallback>();
}

public void Unsubscribe()
{
    callback = null;
}


Then when you need to callback from the service you can just call...

C#
callback.QuestionAnswered(questionThatWasAnswered, answerGiven);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900