troubleshooting Question

How to tranfer interface arrays through wcf service?

Avatar of kankman
kankmanFlag for Germany asked on
.NET ProgrammingC#WCF
3 Comments1 Solution469 ViewsLast Modified:
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);
}

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
					}
			});
	}
}

Interface IDataValidationInfo:

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

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;
	}
}

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?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros