简体   繁体   English

WCF服务对于Silverlight无效

[英]WCF Service invalid with Silverlight

I'm trying to get WCF working with Silverlight. 我正在尝试让WCF与Silverlight一起使用。 I'm a total beginner to WCF but have written asmx services in the past. 我是WCF的初学者,但过去曾编写过asmx服务。 For some reason when I uncomment more than one method in my service Silverlight refuses to let me use it, saying it is invalid. 由于某种原因,当我在服务中取消注释多个方法时,Silverlight拒绝让我使用它,说它无效。 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);
}
}

如果您只是使用WCF将一些数据输入到Silverlight中,那么值得一看的是WCF RIA服务 ,该服务为您构建WCF服务,从而将您的实体暴露给客户端Silverlight。

What does your service reference configuration look like? 您的服务参考配置是什么样的? Remember that SilverLight can only make use of WCF services using http binding. 请记住,SilverLight只能使用通过http绑定的WCF服务。

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. 您需要在类上具有[ServiceContract]属性,或者它需要实现一个具有[ServiceContract]属性的接口,并在该接口上定义的服务方法标有[OperationContract]属性。

You may find that creating a simple "grey screen" Windows Forms application makes it easier to diagnose issues like this. 您可能会发现,创建一个简单的“灰色屏幕” Windows Forms应用程序可以更轻松地诊断此类问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM