I’m trying to get WCF working with Silverlight. I’m a total beginner to WCF but have written asmx services in the past. For some reason when I uncomment more than one method in my service Silverlight refuses to let me use it, saying it is invalid. My code is below if anyone could help. I’m using the Entity Framework if that makes a difference.
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MessageService {//: IMessageService {
/// <summary>
/// Sends a new message.
/// </summary>
/// <param name="recipientUsername">The recipient username.</param>
/// <param name="subject">The subject.</param>
/// <param name="messageBody">The message body.</param>
[OperationContract]
public void SendMessageByDetails(string recipientUsername, string subject, string messageBody) {
MessageDAL.SendMessage(recipientUsername, subject, messageBody);
}
/// <summary>
/// Sends a new message.
/// </summary>
/// <param name="msg">The message to send.</param>
[OperationContract]
public void SendMessage(Message msg) {
MessageDAL.SendMessage(msg);
}
}
You need to have a
[ServiceContract]attribute on the class, or it needs to implement an interface that has a[ServiceContract]attribute and the service methods defined there marked up with[OperationContract]attributes.You may find that creating a simple “grey screen” Windows Forms application makes it easier to diagnose issues like this.