Configurer WCF Client de consommer un Service WCF à l'aide de HTTP GET

J'ai un Service WCF qui autorise uniquement les requêtes HTTP GET:

[WebInvoke(Method="GET", ResponseFormat=WebMessageFormat.Json)]
public string GetAppData()

Le service est accessible à l'aide webHttpBinding

<system.serviceModel>
<bindings>
  <webHttpBinding>
    <binding name="AppSvcBinding">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </webHttpBinding>
</bindings>
    <behaviors>

J'ai mon client dont la config ressemble

<system.serviceModel>
    <client>
        <endpoint address="http://localhost/AppService/Service.svc" 
            binding="webHttpBinding" 
            bindingConfiguration="webHttpBindingConfig"
            contract="AppSvc.IService" 
            behaviorConfiguration="AppSvcBehavior"
            name="AppSvcClient">
    <identity>
      <dns value="localhost"/>
    </identity>
  </endpoint>
    </client>
<bindings>
  <webHttpBinding>
    <binding name="webHttpBindingConfig">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </webHttpBinding>
</bindings>
<behaviors>
  <endpointBehaviors>
    <behavior name="AppSvcBehavior">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
</system.serviceModel>

Mon code client est un simple

ServiceClient client = new ServiceClient("AppSvcClient");
String result = client.GetAppData();

Sur l'exécution de ce code j'obtiens l'erreur:

Le serveur distant a renvoyé une réponse inattendue: (405) Méthode Non Autorisée.

J'ai vérifié avec un violon et constaté que mon client est l'envoi d'un message alors que le service s'attend à un GET d'où l'erreur.

Je voudrais savoir comment configurer le client de sorte que c'est l'envoie de la requête GET pour le service.

Ce que fait le reste de votre côté serveur de configuration?

OriginalL'auteur sandyiit | 2011-02-10