0
데이터를 DB에 저장하려면 WCF API를 사용해야합니다. 일반적으로, 나는 아래의 예처럼, 체인을 사용하십시오 : 이것은 내게 예외가 적시에 던져 내가 검증 이벤트에 반응 할 수 있도록해야 할 가짜 동기 동작을 제공스레딩 패턴 : 체인화 및 루핑
IClientBroker clientBroker = UIContext.CreateWcfInterface<IClientBroker>("Data/ClientBroker.svc");
clientBroker.BeginSetClientBusinessName(_client.ID, businessName, (result) =>
{
_client = ((IClientBroker)result.AsyncState).EndSetClientBusinessName(result);
clientBroker.BeginSetClientAddress(_client.ID, addressObservableCollection, postcodeZip, (result2) =>
{
_client = ((IClientBroker)result2.AsyncState).EndSetClientAddress(result2);
clientBroker.BeginSetClientTelephone(_client.ID, telephone, (result3) =>
{
_client = ((IClientBroker)result3.AsyncState).EndSetClientTelephone(result3);
clientBroker.BeginSetClientFax(_client.ID, fax, (result4) =>
{
_client = ((IClientBroker)result4.AsyncState).EndSetClientFax(result4);
if (customFields.Save(validationSummaryBridge))
{
CloseWindow(true, "ClientID=" + _client.ID.ToString());
}
else
{
validationSummary.Errors.Add(new ValidationSummaryItem("Failed to save Custom Fields"));
}
}, clientBroker);
}, clientBroker);
}, clientBroker);
}, clientBroker);
}
.
그러나 저장할 루프가있을 때 잘 매핑되지 않습니다. 예를 들어, 다음과 같은 "사용자 정의 필드"목록을 저장하는 것이 가장 좋은 패턴은 단일 WCF 호출을 사용하여 각 사용자 정의 필드를 저장해야합니다. 위의 예에서
ICustomFieldsBroker customFieldsBroker = UIContext.CreateWcfInterface<ICustomFieldsBroker>("Data/CustomFieldsBroker.svc");
foreach (CustomField customField in _customFields)
{
string newValue=_customFieldControlDictionary[customField].CustomField.Value;
customFieldsBroker.BeginSetCustomFieldValueForItem(DataTypeID, DataItemID, customField.Key, newValue, (result) =>
{
((ICustomFieldsBroker)result.AsyncState).EndSetCustomFieldValueForItem(result);
}, customFieldsBroker);
}
이 그냥 말, 폼이 닫힌 후에 잠재적으로 돌려 것 WCF의 API/스레드 5 개 요청을 설정합니다. 나는 그들이 "줄을 서"있어야하기 때문에 그들의 상태를 열거하고 양식으로 돌아갈 수 있습니다.
대단히 감사합니다.
WCF가주의를 산만하게하지 마십시오. 그러나 의견이 있으면 알려주십시오. :)
그 코드 형식입니다 .... .... –
그리고 당신의 생산적인 포인트가 될 것 ... 너무 많이 중첩? 코드 캡슐화 수준을 유지하면서 더 나은 방법을 제안하십시오. –