WCF OperationContract - What are Action and ReplyAction?

[ServiceContract(Namespace = "http://schemas.mycompany.com/", Name = "MyService")] public interface IMyService { [OperationContract(Name = "MyOperation") OperationResponse MyOperation(OperationRequest request); } 

In this case, what is the point of Action and ReplyAction ?


Edit: I have to clarify my question ...

How will my wsdl be different if I do not specify these parts? Won't he use any combination of namespace, service name and opeartion name?

+6
source share
3 answers

You only need the Action / ReplyAction properties if you want to configure these values ​​in the messages (and they are reflected in the WSDL). If you do not have them, the default value is <serviceContractNamespace> + <serviceContractName> + <operationName> for Action and <serviceContractNamespace> + <serviceContractName> + <operationName> + "Response" for ReplyAction.

The code below shows the Action / ReplyAction properties for all operations in the service.

 public class StackOverflow_6470463 { [ServiceContract(Namespace = "http://schemas.mycompany.com/", Name = "MyService")] public interface IMyService { [OperationContract(Name = "MyOperation")] string MyOperation(string request); } public class Service : IMyService { public string MyOperation(string request) { return request; } } public static void Test() { string baseAddress = "http://" + Environment.MachineName + ":8000/Service"; ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress)); host.AddServiceEndpoint(typeof(IMyService), new BasicHttpBinding(), ""); host.Open(); Console.WriteLine("Host opened"); foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { Console.WriteLine("Endpoint: {0}", endpoint.Name); foreach (var operation in endpoint.Contract.Operations) { Console.WriteLine(" Operation: {0}", operation.Name); Console.WriteLine(" Action: {0}", operation.Messages[0].Action); if (operation.Messages.Count > 1) { Console.WriteLine(" ReplyAction: {0}", operation.Messages[1].Action); } } } Console.Write("Press ENTER to close the host"); Console.ReadLine(); host.Close(); } } 
+7
source

Sometimes the generated WSDL just isn't right for you. Another interesting task is to set Action = "*" to create an unrecognized message handler.

http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.action.aspx

+1
source

The action determines your uri input for the soap operation for your service method.

ReplyAction defines the output uri for your service method.

They are mainly used to configure uri for both.

  [ServiceContract] public partial interface IServiceContract { [OperationContract( Action = "http://mynamspace/v1/IServiceContract/Input/ServiceMethod", ReplyAction = "http://mynamspace/v1/IServiceContract/Output/ServiceMethod")] SomeResponseType ServiceMethod(SomeRequestType x); 

In your wsdl you will see

  <wsdl:portType name="IServiceContract"> <wsdl:operation name="ServiceMethod"> <wsdl:input wsaw:Action="http://mynamspace/v1/IServiceContract/Input/ServiceMethod" name="SomeRequestType" message="tns:SomeRequestType " /> <wsdl:output wsaw:Action="http://mynamspace/v1/IServiceContract/Output/ServiceMethod" name="SomeResponseType" message="tns:SomeResponseType " /> 
0
source

Source: https://habr.com/ru/post/891301/


All Articles