We consume wcf services in a silverlight application by creating proxies using ChanellFacotry.
The Operation and Data contracts fall under the Silverlight Crough assembly, which consists of shared files from the server document Data and Operation libriary. (omg I hope you understand what I'm saying).
Thus, the server and client use the same operations and data contracts.
Silverlight wcf client lib has a limitation on the impossibility of invoking wcf methods at the same time, as you know, therefore, the collaboration contract file must disclose asyn versions of each operation.
Writing an async WCF service will make sense if they do not contain locking operations, but since we use EF, asynchrony is achieved by delegating the locking operation to the thread pool. This is what WCF does for synchronization anyway. And this fact makes me want to tear my eyes (# @%! ^%! @%).
Our project consultant has the right not to allow the creation of dynamic proxies on the client for calling synchronous contract management methods (if you are interested in Google Evvan Bobrov Servelat Pieces). Thus, we must write senseles functions for asynchronous methods on the server, without any performance increase (blocking calls, as you recall).
Is it possible to call the synchronous wcf web service method from silverlight using a data contract?
- , , ?
, . , - t4, ?
, , async- :
public void Unsubscribe(int organizationId)
{
var clientId = this.OperationContext.GetClientId();
if (string.IsNullOrEmpty(clientId))
{
return;
}
this.InternalUnsubscribe(organizationId, clientId);
}
public IAsyncResult BeginUnsubscribe(int organizationId, AsyncCallback callback, object passThroughData)
{
var clientId = this.OperationContext.GetClientId();
if (string.IsNullOrEmpty(clientId))
{
return null;
}
var asyncResult = new VoidAsyncResult(callback, passThroughData);
Task.Factory.StartNew(() =>
{
try
{
this.InternalUnsubscribe(organizationId, clientId);
asyncResult.SetAsCompleted(false);
}
catch (Exception ex)
{
asyncResult.SetAsCompleted(ex, false);
}
});
return asyncResult;
}
public void EndUnsubscribe(IAsyncResult result)
{
var response = result as VoidAsyncResult;
if (response != null)
{
response.EndInvoke();
}
}