これは、私が尋ねた以前の質問に関連しています。
Transaction クラスを定義する DLL があります。クライアント アプリケーションだけでなく、WCF サービス ライブラリからも参照されます。DLL クラスをシリアル化できないため、サービス ライブラリをホストできないというエラーが表示されます。
サービスコードは次のとおりです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using ServerLibrary.MarketService;
using SharedLibrary; // This is the DLL in question
namespace ServerLibrary
{
[ServiceContract]
public interface IService
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
[OperationContract]
bool ProcessTransaction(SharedLibrary.Transaction transaction);
}
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
ここで [attribute] ヘッダーを使用して Transaction クラスをマークする必要がありますか?
[アップデート]
このサービスをホストしようとすると、次のエラー メッセージが表示されます。
System.Runtime.Serialization.InvalidDataContractException: タイプ 'SharedLibrary.Transaction' をシリアル化できません。これを DataContractAttribute 属性でマークし、シリアル化するすべてのメンバーを DataMemberAttribute 属性でマークすることを検討してください。型がコレクションの場合は、CollectionDataContractAttribute でマークすることを検討してください。サポートされているその他の型については、Microsoft .NET Framework のドキュメントを参照してください。System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException (文字列メッセージ、型の種類) で System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract (Int32 id、RuntimeTypeHandle typeHandle、型の型) で System.Runtime.Serialization.DataContract で。 DataContractCriticalHelper.
ここで要求されているのは、トランザクションを含む DLL です。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SharedLibrary
{
// Transaction class to encapsulate products and checkout data
public class Transaction
{
public int checkoutID;
public DateTime time;
public List<object> products; // Using object to avoid MarketService reference, remember to cast back!
public double totalPrice;
public bool complete;
public Transaction(int ID)
{
checkoutID = ID;
}
public void Start()
{
products = new List<object>();
complete = false;
}
public void Complete()
{
time = DateTime.Now;
complete = true;
}
}
}
ありがとう。