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

このシナリオでは、とのポイントは何ActionですかReplyAction


編集:質問を明確にする必要があります...

これらの部分を指定しない場合、wsdlはどのように異なりますか?とにかく、名前空間、サービス名、操作名の組み合わせを使用するだけではないでしょうか。

4

2 に答える 2

9

メッセージ内のこれらの値をカスタマイズする場合(およびそれらがWSDLに反映される場合)にのみ、Action/ReplyActionプロパティが必要です。それらがない場合、デフォルトは<serviceContractNamespace> + <serviceContractName> + <operationName>Actionと<serviceContractNamespace> + <serviceContractName> + <operationName> + "Response"ReplyActionです。

以下のコードは、サービス内のすべての操作の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();
    }
}
于 2011-06-24T16:52:00.187 に答える
1

生成されたWSDLが適切でない場合があります。実行できる興味深いことの1つは、Action = "*"を設定して、認識されないメッセージハンドラーを作成することです。

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

于 2011-06-24T16:56:17.303 に答える