Link to home
Create AccountLog in
Avatar of kankman
kankmanFlag for Germany

asked on

How to tranfer interface arrays through wcf service?

Hi experts,

following problem:

I have a wcf service, that uses an interface to transfer data:
[ServiceContract]
public interface IAngaraService
{
	[OperationContract]
	[ServiceKnownType(typeof(DataValidationInfo))]
	IDataValidationInfo[] GetAccountValidationInfo(Guid accountId);
		
	[OperationContract]
	[ServiceKnownType(typeof(DataValidationInfo))]
	void SaveAccountDataValidationInfo(IDataValidationInfo dataValidationInfo);
}

Open in new window


Service-implementation:
public class AngaraService : ServiceBase, IAngaraService
{
	public IDataValidationInfo[] GetAccountValidationInfo(Guid accountId)
	{
		DataSetResponse response =
			GetDataSet(new DataSetRequest
				{
					PrimaryKey = accountId,
					TypeName = typeof(AccountDataValidationInfoDataSet).AssemblyQualifiedName
				});

		if (response == null || response.DataSet == null)
		{
			return null;
		}

		AccountDataValidationInfoDataSet validationInfo = new AccountDataValidationInfoDataSet();
		validationInfo.Merge(response.DataSet);

		return validationInfo.DataValidationInfo.Select(r => r as IDataValidationInfo).ToArray();

	}

	public void SaveAccountDataValidationInfo(IDataValidationInfo dataValidationInfo)
	{
		DataSetResponse response =
			GetDataSet(new DataSetRequest
			{
				PrimaryKey = dataValidationInfo.PrimaryKey,
				TypeName = typeof(AccountDataValidationInfoDataSet).AssemblyQualifiedName
			});

		AccountDataValidationInfoDataSet dataSet = new AccountDataValidationInfoDataSet();
		dataSet.Merge(response.DataSet);
		dataSet.AcceptChanges();

		AccountDataValidationInfoDataSet.DataValidationInfoRow row =
			dataSet.DataValidationInfo.FirstOrDefault(r => r.DataValidationTarget == DataValidationInfoTargetType.Kommunikation);

		if (row == null)
		{
			DataSetResponse accountResponse =
				GetDataSet(new DataSetRequest
				{
					PrimaryKey = dataValidationInfo.PrimaryKey,
					TypeName = typeof(AccountDataSet).AssemblyQualifiedName
				});

			if (accountResponse.DataSet == null || accountResponse.DataSet.Tables.Count == 0)
			{
				throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "AccountID \"{0}\" not found.",
																  dataValidationInfo.PrimaryKey));
			}

			row = dataSet.DataValidationInfo.NewDataValidationInfoRow();

			AccountDataValidationInfoDataSet.AccountRow accRow = dataSet.Account.NewAccountRow();
			accRow.AccountID = dataValidationInfo.PrimaryKey;
			row.AccountRow = accRow;

			row.PrimaryKeyID = dataValidationInfo.PrimaryKey;
			row.DataValidationInfoID = Guid.NewGuid();
			row.DataValidationInfoSourceTypeId = dataValidationInfo.PrimaryKeySource.GetGuid();
			row.DataValidationInfoTargetTypeId = dataValidationInfo.DataValidationTarget.GetGuid();
			
			row.LastValidationTime = DateTime.Now;
			
			dataSet.DataValidationInfo.AddDataValidationInfoRow(row);

			dataSet.Account.AcceptChanges(); //Row als Accepted markieren, damit der Account nich tneu angelegt wird
		}

		row.LastValidationTime = dataValidationInfo.LastValidationTime;

		UpdateDataSet(new[]
			{
				new DataSetUpdateRequest
					{
						ChangesDataSet = dataSet.GetChangesReal(),
						TypeName = typeof (AccountDataValidationInfoDataSet).AssemblyQualifiedName
					}
			});
	}
}

Open in new window


Interface IDataValidationInfo:

public interface IDataValidationInfo
{
	DataValidationInfoSourceType PrimaryKeySource //enum
	{
		get;
	}
	Guid PrimaryKey
	{
		get;
	}
	DateTime LastValidationTime
	{
		get;
	}
	DataValidationInfoTargetType DataValidationTarget //enum
	{
		get;
	}
}

Open in new window


DataValidationObject:

[DataContract]
public class DataValidationInfo : IDataValidationInfo
{
	[DataMember]
	public DataValidationInfoSourceType PrimaryKeySource //enum
	{
		get;
		set;
	}
	[DataMember]
	public Guid PrimaryKey
	{
		get;
		set;
	}
	[DataMember]
	public DateTime LastValidationTime
	{
		get;
		set;
	}
	[DataMember]
	public DataValidationInfoTargetType DataValidationTarget //enum
	{
		get;
		set;
	}
}

Open in new window


Here is the problem:
The Save method works. The Get-method does not work an throws an System.ServiceModel.CommunicationException with no additional information.

What do I do wrong?
SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of kankman

ASKER

I found the solution my self after trying some more.