Hi all,

My problem is that my android client cannot do a post action to a wcf
json service.

i have verified that the wcf json service works by invoking it with a
client written in c# and through fiddler.

Every time i call this service via the android java code, i always get
this error: "http://1.1 405 Method Not Allowed"
I just do not know what the heck i am doing wrong.

if you could, please help.  thank you in advance.

// ###################################################
// here is the java client
// ###################################################
    ServiceRequest serviceRequest = new ServiceRequest();
    serviceRequest.SetAccessKey("ee404d54-
ea45-421a-9633-1ea35c0c211e");
    serviceRequest.SetFbAccessToken("2227470867|2.AQAeyiaJuxTmsRqi.
3600.1310490000.0-757629911|Mz1JFuTONIf0y84AEuTxcWgYPzI");
    serviceRequest.SetType("c");
    serviceRequest.SetPlatform("a");
    // request.SetData(encodedData);

    // serialize
    Gson gson = new Gson();
    String data = gson.toJson(serviceRequest);

    try {
      HttpClient httpClient = new DefaultHttpClient();
      HttpPost request = new HttpPost("http://simpleapp.dyndns.org:81/
voicebook");

      StringEntity entity = new StringEntity(data, "utf-8");
      entity.setContentType("application/json");
      entity.setContentEncoding("utf-8");
      request.setEntity(entity);

      request.setHeader("content-type", "application/json");

      HttpResponse response = httpClient.execute(request);

      TextView tvName = (TextView) findViewById(R.id.tvName);
      tvName.setText(String.valueOf(response.getStatusLine()));

    } catch (UnsupportedEncodingException e) {
      TextView tvName = (TextView) findViewById(R.id.tvName);
      tvName.setText(e.getMessage());
    } catch (ClientProtocolException e) {
      TextView tvName = (TextView) findViewById(R.id.tvName);
      tvName.setText(e.getMessage());
    } catch (IOException e) {
      TextView tvName = (TextView) findViewById(R.id.tvName);
      tvName.setText(e.getMessage());
    }

// ###################################################
// ###################################################

// ###################################################
// here's the serialized json ServiceRequest object
// ###################################################
{"accessKey":"ee404d54-
ea45-421a-9633-1ea35c0c211e","fbAccessToken":"2227470867|
2.AQA19SOnrUjqRy-Y.3600.1310454000.0-757629911|lpHIBB-
ghCPt73ZlaDtWDmOcro0","type":"c","platform":"a"}
// ###################################################
// ###################################################



// ###################################################
// here is the signature of the wcf json service
// ###################################################

    [OperationContract]
    [WebInvoke(UriTemplate = "", Method = "POST", RequestFormat =
WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
    public ServiceResponse Create(ServiceRequest request) {

// do something


}
// ###################################################
// ###################################################


// ###################################################
// here is the serviceRequest object
// ###################################################

using System.IO;
using System.Runtime.Serialization;

namespace VoicebookService.Request {

  [DataContract()]
  public class ServiceRequest {

    #region private member
    [DataMember(IsRequired = true)]
    private string accessKey; // access key for this service

    [DataMember(IsRequired = true)]
    private string fbAccessToken; // fb live access token

    [DataMember(IsRequired = true)]
    private string type; // c for comment : m for message

    [DataMember(IsRequired = true)]
    private string platform; // a for android : i for ios : w for
window

    [DataMember(IsRequired = false)]
    private string data; // the file to be save to s3
    #endregion

    #region property
    public string AccessKey {
      set {
        this.accessKey = value;
      }
      get {
        return this.accessKey;
      }
    }

    public string FbAccessToken {
      set {
        this.fbAccessToken = value;
      }
      get {
        return this.fbAccessToken;
      }
    }

    public string Type {
      set {
        this.type = value;
      }
      get {
        return this.type;
      }
    }

    public string Platform {
      set {
        this.platform = value;
      }
      get {
        return this.platform;
      }
    }

    public string Data {
      set {
        this.data = value;
      }
      get {
        return this.data;
      }
    }
    #endregion

  }
}

// ###################################################
// ###################################################

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to