0

I have a duplex WCF service that clients connect to and wait for commands. The structure of the application is as below.

GUI(Asp.net)------------>WCF Service------------------>WCF Client

The from Asp.net pages you can run Gallio/MB Unit Tests. Those are passed to the Service and the service asks the client(s) to run the tests. It's all working good. What i want to implement now is to update the Asp.net application with the status of the test.

So if the user wants to run a whole assembly of tests at least i should know on the Asp.NET application which test is running and possibly the percentage of the test that is completed.

Any help on how to go about this / what approach to take is greatly appreciated.

Thanks

Abdul Waheed
  • 136
  • 1
  • 6

2 Answers2

2

You need to define a callback contract and implement it in your ASP.Net website. You also need to use wsDualHttpBinding to add support for duplex operations.

public interface ITransferAck{
    [OperationContract(IsOneWay = true)]
    void TransferRecordResendRequest(int transferId); 
}
[ServiceContract(CallbackContract=typeof(ITransferAck))]
public interface IBankTransfer{
    [OperationContract(IsOneWay=true)]
    void ExchangeTransferRecord(int transferId, string record);
}

The service communicates with the client application through a proxy reference that it obtains from OperationContext, as the following code examples show.

client = OperationContext.Current.GetCallbackChannel<ITransferAck>(); 

client.TransferRecordResendRequest(1); 
Nima M
  • 718
  • 10
  • 18
  • Nima, Thanks for the reply. I already have a callback contract defined for Asp.net app and the Wcf Client. After the tests have completed the WCF client updates teh service and the service updates teh asp.net app. The problem i have is real-time updating. i want to show on asp.net app what is going on on wcf client. for example which test is running and what percentage of the test assembly is completed – Abdul Waheed Feb 15 '11 at 19:33
  • Abdul Waheed, can you retrieve the percentage in your WCF client application? – Nima M Feb 15 '11 at 19:38
  • WCF client is running Gallio.Echo to run tests. yes i can get the status from Gallio.Echo on the tests. What is the best approach to use in order to update the client and let's say if the client crashes or something like that. – Abdul Waheed Feb 15 '11 at 19:47
  • Well, the best approach for managing crashes is define custom faultExceptions and throw them if the application crashed.(I'll post a new answer and explain these) For sending the status to ASP.Net website, as far as I know, Using callback contracts is the best way. – Nima M Feb 15 '11 at 20:15
2

SOAP fault is a mechanism for transferring error or fault conditions from a service to a consumer. The SOAP specification includes a definition for SOAP faults, providing structure for the contents of the message body when errors occur. This makes it possible for all the different SOAP stacks to issue faults in a standard way.

FaultException Used to send untyped fault data back to the consumer.

FaultException<TDetail> A generic version used to send typed fault data back to the client, where TDetail represents the type parameter for the detailed fault information to be serialized back to the consumer as part of the SOAP fault message.

The FaultContractAttribute The FaultContractAttribute, also defined in System.ServiceModel, enables a service developer to declare which faults a given service operation might issue if things go wrong. Following are the key pieces of information pertinent to working with the FaultContractAttribute:

The attribute can be applied to operations only.
The attribute is not inherited.
The attribute can be applied multiple times; for instance, if your service operation might return different types of faults, you would have a FaultContractAttribute declaration for each type of fault.

The attribute’s constructor takes a Type object used to reference the .NET type of the Detail object, that is, the type of fault information details you want to bundle with your faults.

[ServiceContract()]
public interface ICalculatorService{
[OperationContract()]
[FaultContract(typeof(string))]
double Divide(double numerator, double denominator);
}
public class CalculatorService : ICalculatorService {
public double Divide(double numerator, double denominator) {
if (denominator == 0.0d) {
string faultDetail = "You cannot divide by zero";
throw new FaultException<string>(faultDetail);
}
return numerator / denominator;
}
}

*Please note that instead string class in this example you can define your own custom exception class.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Nima M
  • 718
  • 10
  • 18