views:

72

answers:

3

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);
}
}
A: 

If you're just using WCF to get some data into Silverlight it may be worth looking at WCF RIA Services which constructs the WCF service for you end exposes your entities to your client side Silverlight.

jbloomer
A: 

What does your service reference configuration look like? Remember that SilverLight can only make use of WCF services using http binding.

David Hay
A: 

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.

Jeremy McGee
I now receive a different cryptic error - Custom tool error: Failed to generate code for the service reference 'MessageService'. Please check other error and warning messages for details. C:\Users\Echilon\Documents\Coding\MessageCentre\MessageCentre\Service References\MessageService\Reference.svcmap
Echilon
@Echilon - check the output from the build in Visual Studio.
Jeremy McGee
Oddly, it seems to work now. I must have missed an apostrophe or made a typo somewhere.
Echilon