Code inspection: One way operations must not return values
Category: Potential Code Quality Issues
ID: OneWayOperationContractWithReturnType
EditorConfig: resharper_one_way_operation_contract_with_return_type_highlighting=[error|warning|suggestion|hint|none]
Language: C#
Requires SWA: No
tip
This inspection reports violations of the IsOneWay=true
contract in the System.ServiceModel.OperationContract
context.
The IsOneWay=true contract is used in Windows Communication Foundation (WCF) to indicate that an operation should be invoked in a fire-and-forget manner, which means that the client does not wait for a response from the server after invoking the operation.
If a non-void method is annotated this way, you have an inconsistency that might indicate an error.
There are two ways to fix that:
If your intention is to receive a response from the service, remove the IsOneWay=true
contract:
Suboptimal code
[OperationContract(IsOneWay=true)]public string GetString(){ return "something";}
After the quick-fix
[OperationContract]public string GetString(){ return "something";}
If you intend to keep the one-way operation behavior and don't need the return value, modify the method to return void
instead:
Suboptimal code
[OperationContract(IsOneWay=true)]public string GetString(){ return "something";}
After the quick-fix
[OperationContract(IsOneWay=true)public void GetString(){ /*Do something*/}