使用 System.Array 作为 DataMember 时 WCF AJAX 响应失败
当我尝试获取 Sytem.Array 作为 Json 类对象中的数据成员时,它会给出失败响应。
我的 WCf Web 服务正在使用以下方法 userActivities
,该方法返回类 Activity
。我已在 Ajax 类 Activity
中设置参数。
[ServiceContract]
public interface IMyService
{
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
Activity userActivities(Activity activity, string action);
}
[DataContract]
partial class Activity
{
}
在 MyService.cs 中,服务类是
public Activity userActivities(Activity activity, string action)
{
if (action.ToLower() == "myactivities")
{
activity.get_MyActivities();
}
return activity;
}
,活动类是:
[DataMember]
public int userID;
[DataMember]
public Array _getList_MyActivities;
public void get_MyActivities()
{
_DL_Activity = new DL_Activity();
if (this.userID > 0)
this._getList_MyActivities = _DL_Activity.get_MyActivity(this.userID);
}
When i m trying to get Sytem.Array
As data member in Json Class object it gives failure response .
My WCf web-service i am using following method userActivities
which return class Activity
.I have set parameter in class Activity
from Ajax .
[ServiceContract]
public interface IMyService
{
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
Activity userActivities(Activity activity, string action);
}
[DataContract]
partial class Activity
{
}
And in the MyService.cs Class of Service is
public Activity userActivities(Activity activity, string action)
{
if (action.ToLower() == "myactivities")
{
activity.get_MyActivities();
}
return activity;
}
And Class Activity is :
[DataMember]
public int userID;
[DataMember]
public Array _getList_MyActivities;
public void get_MyActivities()
{
_DL_Activity = new DL_Activity();
if (this.userID > 0)
this._getList_MyActivities = _DL_Activity.get_MyActivity(this.userID);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
得到这篇文章。根据此尝试使用
ServiceKnownType
装饰您的服务。像这样的
根据您的评论,您在数组中存储不同的数据类型,我想您需要将数组中的所有项目的
typeof
作为ServiceKnownType
。希望这对你有用。
Got this post. According to this try decorating your service with
ServiceKnownType
.Something like this
According to your comment you are storing different data types in the array, I guess you will need to put
typeof
for all items in array asServiceKnownType
.Hope this works for you.