我的属性 knowntype 不支持错误操作
Error Operation not supported with my attributes knowntype
我已经在 link Operation not supported in the WCF Test Client
中阅读过这篇文章
我尝试 运行 这个
时出错
the operation is not supported in the WCF GetBatch()
这是我的类解决方法
[KnownType(typeof(Contract))]
[KnownType(typeof(TotalAmount))]
[KnownType(typeof(SubjectRole))]
[KnownType(typeof(ContractData))]
[KnownType(typeof(MonthlyPayment))]
[KnownType(typeof(ProlongationAmount))]
[DataContract]
public class Batch
{
private string batchIdentifierField;
private Contract contractField;
[DataMember]
public string BatchIdentifier
{
get { return this.batchIdentifierField;}
set { this.batchIdentifierField = value;}
}
[DataMember]
public Contract Contract
{
get { return this.contractField;}
set { this.contractField = value;}
}
}
[DataContract(Name = "Contract")]
public partial class Contract
{
\\other fields
[DataMember]
public ContractData ContractData{get;set;}
[DataMember]
public SubjectRole[] SubjectRole{get;set;}
\\other fields
}
[DataContract(Name = "ContractData")]
public partial class ContractData
{
\\other fields
[DataMember]
public TotalAmount TotalAmount{get;set;}
[DataMember]
public MonthlyPayment TotalMonthlyPayment{get;set;}
[DataMember]
public ProlongationAmount ProlongationAmount{get;set;}
\\other fields
}
[DataContract(Name = "TotalAmount")]
public partial class TotalAmount{}
[DataContract(Name = "MonthlyPayment")]
public partial class MonthlyPayment{}
[DataContract(Name = "ProlongationAmount")]
public partial class ProlongationAmount{}
界面
[ServiceContract]
public interface IBankService
{
[OperationContract]
Batch GetBatch(string DateTime);
[OperationContract]
string AddBatch(Batch entityBatch);
[OperationContract]
string AddLocalBatch(string localPath);
[OperationContract]
string Ping();
}
这是有效的方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using ModelContract;
using DABatch;
namespace WCF_Service
{
// Realization my Methods
public class BankService : IBankService
{
public Batch GetBatch(string datetime)
{
try
{
DateTime date = DateTime.Parse(datetime);
if (datetime.IsEmpty())
{
Debug.WriteLog("Field Datetime is Empty");
return new Batch();
}
using (BatchContext db = new BatchContext())
{
if (db.DBBatches.Any(x => x.Contract.ContractData.StartDate.Equals(date)))
{
//.......
return ChangedBatch;
}
else
{
//Just insert Time and create new object
//......
return newBatch;
}
}
}
catch(Exception ex)
{
Debug.WriteLog(ex.Message);
return new Batch();
}
}
public string AddBatch(Batch entityBatch)
{
try
{
if (entityBatch == null)
{
Debug.WriteLog("Batch entity is Empty", new NullReferenceException());
return "Error : Batch entity is Empty, nothing to Load";
}
using (BatchContext db = new BatchContext())
{
db.DBBatches.Add(entityBatch);
return "Add Operation Success!";
}
}
catch(Exception ex)
{
Debug.WriteLog(ex.Message);
return string.Format($"Error : {ex.Message}");
}
}
public string AddLocalBatch(string localPath)
{
try
{
if (localPath.IsEmpty())
{
Debug.WriteLog("Link is Empty");
return "Error : Link is Empty, nothing to Load";
}
var entityBatch = XmlReader.Read(localPath);
using (BatchContext db = new BatchContext())
{
db.DBBatches.Add(entityBatch);
return "Add Operation Success!";
}
}
catch (Exception ex)
{
Debug.WriteLog(ex.Message);
return string.Format($"Error : {ex.Message}");
}
}
public string Ping()
{
return string.Format($"Service is working. OK! Date : {DateTime.Now.ToLongDateString()} Time: {DateTime.Now.ToLongTimeString()}");
}
}
AddLocalBatch 正在运行。
我不知道在这个问题中添加什么。
我尝试了this link中的所有方法。
WCFTestclient不支持测试所有接口方法,例如上传文件流。也不代表方法定义错误,不能调用。
建议大家直接把服务以服务引用的形式添加到项目中,然后测试是否有效。
KnownTypeAttribute 不适用于这种情况。因为您明确指定了数据协定 属性 的强类型 class,而不是基本类型或接口。
如果有什么我可以帮忙的,请随时告诉我。
我已经在 link Operation not supported in the WCF Test Client
中阅读过这篇文章我尝试 运行 这个
时出错the operation is not supported in the WCF GetBatch()
这是我的类解决方法
[KnownType(typeof(Contract))]
[KnownType(typeof(TotalAmount))]
[KnownType(typeof(SubjectRole))]
[KnownType(typeof(ContractData))]
[KnownType(typeof(MonthlyPayment))]
[KnownType(typeof(ProlongationAmount))]
[DataContract]
public class Batch
{
private string batchIdentifierField;
private Contract contractField;
[DataMember]
public string BatchIdentifier
{
get { return this.batchIdentifierField;}
set { this.batchIdentifierField = value;}
}
[DataMember]
public Contract Contract
{
get { return this.contractField;}
set { this.contractField = value;}
}
}
[DataContract(Name = "Contract")]
public partial class Contract
{
\\other fields
[DataMember]
public ContractData ContractData{get;set;}
[DataMember]
public SubjectRole[] SubjectRole{get;set;}
\\other fields
}
[DataContract(Name = "ContractData")]
public partial class ContractData
{
\\other fields
[DataMember]
public TotalAmount TotalAmount{get;set;}
[DataMember]
public MonthlyPayment TotalMonthlyPayment{get;set;}
[DataMember]
public ProlongationAmount ProlongationAmount{get;set;}
\\other fields
}
[DataContract(Name = "TotalAmount")]
public partial class TotalAmount{}
[DataContract(Name = "MonthlyPayment")]
public partial class MonthlyPayment{}
[DataContract(Name = "ProlongationAmount")]
public partial class ProlongationAmount{}
界面
[ServiceContract]
public interface IBankService
{
[OperationContract]
Batch GetBatch(string DateTime);
[OperationContract]
string AddBatch(Batch entityBatch);
[OperationContract]
string AddLocalBatch(string localPath);
[OperationContract]
string Ping();
}
这是有效的方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using ModelContract;
using DABatch;
namespace WCF_Service
{
// Realization my Methods
public class BankService : IBankService
{
public Batch GetBatch(string datetime)
{
try
{
DateTime date = DateTime.Parse(datetime);
if (datetime.IsEmpty())
{
Debug.WriteLog("Field Datetime is Empty");
return new Batch();
}
using (BatchContext db = new BatchContext())
{
if (db.DBBatches.Any(x => x.Contract.ContractData.StartDate.Equals(date)))
{
//.......
return ChangedBatch;
}
else
{
//Just insert Time and create new object
//......
return newBatch;
}
}
}
catch(Exception ex)
{
Debug.WriteLog(ex.Message);
return new Batch();
}
}
public string AddBatch(Batch entityBatch)
{
try
{
if (entityBatch == null)
{
Debug.WriteLog("Batch entity is Empty", new NullReferenceException());
return "Error : Batch entity is Empty, nothing to Load";
}
using (BatchContext db = new BatchContext())
{
db.DBBatches.Add(entityBatch);
return "Add Operation Success!";
}
}
catch(Exception ex)
{
Debug.WriteLog(ex.Message);
return string.Format($"Error : {ex.Message}");
}
}
public string AddLocalBatch(string localPath)
{
try
{
if (localPath.IsEmpty())
{
Debug.WriteLog("Link is Empty");
return "Error : Link is Empty, nothing to Load";
}
var entityBatch = XmlReader.Read(localPath);
using (BatchContext db = new BatchContext())
{
db.DBBatches.Add(entityBatch);
return "Add Operation Success!";
}
}
catch (Exception ex)
{
Debug.WriteLog(ex.Message);
return string.Format($"Error : {ex.Message}");
}
}
public string Ping()
{
return string.Format($"Service is working. OK! Date : {DateTime.Now.ToLongDateString()} Time: {DateTime.Now.ToLongTimeString()}");
}
}
AddLocalBatch 正在运行。
我不知道在这个问题中添加什么。
我尝试了this link中的所有方法。
WCFTestclient不支持测试所有接口方法,例如上传文件流。也不代表方法定义错误,不能调用。
建议大家直接把服务以服务引用的形式添加到项目中,然后测试是否有效。
KnownTypeAttribute 不适用于这种情况。因为您明确指定了数据协定 属性 的强类型 class,而不是基本类型或接口。
如果有什么我可以帮忙的,请随时告诉我。