kankman
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:
Service-implementation:
Interface IDataValidationInfo:
DataValidationObject:
Here is the problem:
The Save method works. The Get-method does not work an throws an System.ServiceModel.Commun icationExc eption with no additional information.
What do I do wrong?
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.Commun
What do I do wrong?
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER