如果您想要自定義消息中的這些值(並且它們反映在WSDL中),則只需要Action/ReplyAction屬性。如果您沒有它們,Action的默認值爲<serviceContractNamespace> + <serviceContractName> + <operationName>
,ReplyAction的默認值爲<serviceContractNamespace> + <serviceContractName> + <operationName> + "Response"
。
下面的代碼打印出服務中所有操作的Action/ReplyAction屬性。
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();
}
}
所以相當多,如果我做了'ReplyAction = 「http://schemas.mycompany.com/MyService/MyOperation」'這將是相同的它建立在它自己的? – michael
不,回覆操作應該是「http://schemas.mycompany.com/MyService/MyOperationResponse」。我將通過如何打印操作的操作/回覆操作屬性來更新答案。 – carlosfigueira
對不起,我的意思是'Action'和'ReplyAction'是相同的,但附加了「Response」。 – michael