我正在使用WCF服务开发web应用程序,我已经创建了服务并在客户端应用程序中使用了该服务,我正在为上传一个文本文件
上传txt文件后匹配文件,我在客户端页面上得到以下错误
尝试序列化参数时出错http://tempuri.org/:lblHide.InnerException消息为"Type"ASP.WCFApp_aspx",包含数据合同名称'WCFApp_aspx:http://schemas.datacontract.org/2004/07/ASP不应为"。考虑使用DataContractResolver或添加任何未对已知类型列表静态已知-例如,通过使用KnownTypeAttribute属性或将它们添加到传递给DataContractSerializer.'。有关详细信息,请参阅InnerException。--->System.Runtime.Serialization.Serialization异常:类型"ASP.WCFApp_aspx"数据协定名称为"WCFApp"_aspx://schemas.datacontract.org/2004/07/ASP不应为"。考虑使用DataContractResolver或添加已知类型列表中静态未知的类型-例如,通过使用KnownTypeAttribute属性或将它们添加到已知类型列表传递给DataContractSerializer
请参阅下面的代码,WCFService.cs:
【运营合同】
[ServiceKnownType(typeof(string))]
[ServiceKnownType(typeof(List<string>[]))]
string KeyFieldsMatch(List<string>[] lst, Label lblHide, string strConn);
IWCFService.svc.cs:
public class WCFService: IWCFService
{
public string KeyFieldsMatch(List<string>[] lst, Label lblHide, string strConn)
{
try
{
return objBAL.KeyFieldsMatch(lst, lblHide, strConn);
}
catch
{
throw new FaultException("Error....");
}
}
}
客户:
WCFService.WCFServiceClient objBAL = new WCFService.WCFServiceClient();
protected void btnSubmit_Click(object sender, EventArgs e)
{
List<string>[] list = new List<string>[2]
string[][] lst = new string[2][];
lst = list.Select(a => a.ToArray()).ToArray();
string KeyFieldsMatch =string.empty;
KeyFieldsMatch = objBAL.KeyFieldsMatch(lst, lblHide, strConn);--Error coming at this location.
}
我正在使用basicHttpBinding
如有任何帮助,我们将不胜感激。
您正在将一个UI对象传递给WCF服务。您应该做的是只将标签的文本值作为字符串传递,而不是完整的标签,因为这是一种过度使用和糟糕的做法。只发送您需要的内容。