rspec/rules/S3597/csharp/rule.adoc

47 lines
1.3 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
The ``++ServiceContract++`` attribute specifies that a class or interface defines the communication contract of a Windows Communication Foundation (WCF) service. The service operations of this class or interface are defined by ``++OperationContract++`` attributes added to methods. It doesn't make sense to define a contract without any service operations; thus, in a ``++ServiceContract++`` class or interface at least one method should be annotated with ``++OperationContract++``. Similarly, WCF only serves ``++OperationContract++`` methods that are defined inside ``++ServiceContract++`` classes or interfaces; thus, this rule also checks that ``++ServiceContract++`` is added to the containing type of ``++OperationContract++`` methods.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
[ServiceContract]
interface IMyService // Noncompliant
{
int MyServiceMethod();
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
[ServiceContract]
interface IMyService
{
[OperationContract]
int MyServiceMethod();
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]