tags:

views:

52

answers:

3

I have developed some basic web services using WCF. So far the return types have been fairly simple. Here are the Operation contracts that are working correctly:

[OperationContract]
string Vessel(int ID);

//lists all vessel
[OperationContract]
List<string> Vessels();

[OperationContract]
List<string> PortsLike(string LikeStr);

[OperationContract]
Port GetPort(string name);

These have worked beautifully. I have now tried to push the envelope a bit and tried the following:

[OperationContract]
List<Pair> Vessels(List<string> fields, List<Criterion> criteria); 

Where Pair and Criterion are pretty basic classes that I defined.

unfortunately this latest Operation does not compile. Is this because I have reached the limits of what can be accommodated by web services or am I doing something obviously wrong?

Here are the definitions for Pair and Criterion:

[DataContract]
public class Criterion
{
    [DataMember]
    public string Key { get; set; }
    [DataMember]
    public string Operator { get; set; }
    [DataMember]
    public string Value { get; set; }
}

[DataContract]
public class Pair
{
    [DataMember]
    public string Key { get; set; }

    [DataMember]
    public string Value { get; set; }

    public Pair(string key, string value)
    {
        this.Key = key;
        this.Value = Value;
    }
}

Here is the error I get from the compiler:

Error 1 'VOps.VOpsService' does not implement interface member 'VOps.IVOpsService.Vessels(System.Collections.Generic.List, System.Collections.Generic.List)'. 'VOps.VOpsService.Vessels(System.Collections.Generic.List, System.Collections.Generic.List)' cannot implement an interface member because it is not public.

A: 

Have you decorated Pair and Criterion with DataContract attributes + decorated their properties with DataMember attributes?

vc 74
Yes. Updated question with definitions
Ren
You Pair class should have a parameterless constructor
vc 74
Mmm, ok. That was actually a late edition in my attempt to get it working. So even without the constructor decorated it does not work. Edited question.
Ren
Is your operation in the service implementation public? According to the error message, it is private and therefore your implementation cannot implement the interface.
vc 74
Ok found error. Kinda obvious but as you mentioned I did not declare the service implementation public. Sadly it was pretty obvious.
Ren
Glad to see it works now.
vc 74
A: 

You should not have [DataMember] on the Pair constructor

Eugene Osovetsky
Also, what is the exact error message you're getting?
Eugene Osovetsky
refer to above comment, did not work without constructor decorator
Ren
A: 

I did not declare the service implementation as public.

Ren