2016-04-26 11 views
1

私はWCFを非常に新しくしており、それについて質問があります。WCFサービスをSOAPからRESTに変換するにはどうすればよいですか?

私は、webHttpBindingとhttpGetEnabledからwebHttpBindingへのエンドポイントバインディングをtrueからfalseに変更すると、web.configファイルでRESTを使用していることが判明しました。

私の質問は、サービスSOAPまたはRESTを作成するために変更する必要があるのはこれら2つだけですか?あるいは、他のものを変更/追加する必要がありますか?

答えて

4

2つの異なるエンドポイントでサービスを公開できます。例えば、SOAPをサポートするバインディングを使用することができる。 basicHttpBindingRESTwebHttpBindingを使用できます。私はそのような場合には、次の動作設定で2つのエンドポイントを設定する必要があり、あなたのRESTサービスはJSONになりますと仮定

<endpointBehaviors> 
    <behavior name="jsonBehavior"> 
    <enableWebScript/> 
    </behavior> 
</endpointBehaviors> 

あなたのシナリオでは、エンドポイント構成の例は、

<services> 
    <service name="TestService"> 
    <endpoint address="soap" binding="basicHttpBinding" contract="ITestService"/> 
    <endpoint address="json" binding="webHttpBinding" behaviorConfiguration="jsonBehavior" contract="ITestService"/> 
    </service> 
</services> 

が適用されます操作契約に[WebGet]を入力してRESTfulにします。例えばサービス参照を追加した後のSOAPサービスの

public interface ITestService 
{ 
    [OperationContract] 
    [WebGet] 
    string HelloWorld(string text) 
} 

SOAPリクエストクライアントエンドポイントの設定、httpgetenabledがtrueまたはfalseに設定について

<client> 
    <endpoint address="http://www.example.com/soap" binding="basicHttpBinding" 
     contract="ITestService" name="BasicHttpBinding_ITestService" /> 
    </client> 
C#で

TestServiceClient client = new TestServiceClient(); 
client.GetAccount("A123"); 
+0

そして、何?私も同様にこれを変更する必要がありますか? – Rakesh

関連する問題