Default Action for your [OperationContract]

Question of the Day: what is the action for my OperationContract?

Answer: if not set explicitly, the action is contractNamespace + contractName + “/” + operationName. For responses, tack on “Response” at the end of this string.

By default, contractNamespace == “http://tempuri.org/”, contractName == class name, and operationName == method name. These names can be specified explicitly through ServiceContractAttribute.Namespace, ServiceContractAttribute.Name, and OperationContractAttribute.Name respectively.

As an example, if you have the following operation:

[ServiceContract]
class MyService
{
[OperationContract]
public string SampleHello(string name)
{
return string.Format(”Hello {0}.”, name);

}

}

the request action is http://tempuri.org/MyService/SampleHello, and the response action is http://tempuri.org/MyService/SampleHelloResponse.

Alternatively, you can specify the action(s) of your method with the Action and ReplyAction parameters to OperationContract (i.e. [OperationContract(Action=”myAction”, ReplyAction=”myReplyAction”)]

2 Responses to “Default Action for your [OperationContract]”

  1. mattonsoftware.com : .NET Resources Says:

    […] […]

  2. kennyw.com » Blog Archive » Using Overloaded Operations in your ServiceContract Says:

    […] It may be that you’ve done your service-oriented scrub and decided you want to expose two overloaded methods. From a service-orientation perspective, the compiler isn’t adding extra qualifications to differentiate the methods. Our default action generation is based on the operation name, which defaults to the name of your method. As such, in order for a client (and our dispatcher) to distinguish between multiple overloaded methods, you need to provide them with unique names. For example: [ServiceContract] interface ICalculator { [OperationContract(Name= “Add_Int”)] int Add(int x, int y); […]

Leave a Reply