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 thoughts on “Default Action for your [OperationContract]

  1. Pingback: mattonsoftware.com : .NET Resources

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

Leave a Reply

Your email address will not be published. Required fields are marked *