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

このシナリオでは、ActionReplyActionのポイントは何ですか?WCF OperationContract - ActionとReplyActionのポイントは何ですか?


編集:私は、私はこれらの部品を指定しない場合、私のWSDLが異なるだろうか...

を私の質問を明確にする必要がありますか?とにかく、名前空間、サービス名、opeartion名の組み合わせを使用するだけではありませんか?

答えて

7

メッセージの値をカスタマイズする場合(WSDLに反映されている場合のみ)、アクション/ ReplyActionプロパティが必要です。あなたが持っていない場合、デフォルトはアクションの場合は<serviceContractNamespace> + <serviceContractName> + <operationName>、返信の場合は<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(); 
    } 
} 
+0

だから、かなり多くのを見るでしょうそれを自分の上にそれを構築するには? – michael

+1

いいえ、返信アクションは「http://schemas.mycompany.com/MyService/MyOperationResponse」です。操作のアクション/応答アクションのプロパティを出力する方法についての回答を更新します。 – carlosfigueira

+0

申し訳ありませんが、私は 'Action'と' ReplyAction'は同じであるが、 'Response'が追加されていることを意味しました。 – michael

1

場合によっては、生成されたWSDLがあなたに適していないことがあります。興味深いのは、アクション= "*"を設定して、認識できないメッセージハンドラを作成することです。

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

+1

「認識されないメッセージハンドラ」を作成したいのはなぜですか? – michael

+3

あなたは確かに彼を困らせました、マイケル!ほぼ2年間、彼はまだそれについて考えています! :P – seekerOfKnowledge

+6

@michael私はそれが "認識できない_メッセージハンドラ_"ではなく "_unrecognized message_handler"だと信じています。 –

0

アクションは、あなたのサービスメソッドのSOAP操作のためのあなたの入力URIを定義します。

ReplyActionは、あなたのサービス方法のために出力uriを定義します。

これらは基本的に両方のURIをカスタマイズするために使用されます。あなたのWSDLで

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

私は `ReplyAction = "http://schemas.mycompany.com/MyService/MyOperationを" なかった場合、`それは同じだろう

<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 " /> 
関連する問題