2

The problem is I cannot call my wcf json service with my android client. I am able to call my wcf json service with my c# client and fiddler, with the same exact request parameter.

Everytime i try calling the service with my android client i would get this error: "HTTP/1.1 405 Method Not Allowed."

i've done all the research both here and on google android developer group, but I still cannot get my code working correctly.

I just don't know what the problem any more, if someone could, please help.

Thank you in advance.

// ####################################
// android 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 is the sample serialized json object
// ####################################

{"accessKey":"ee404d54-ea45-421a-9633-1ea35c0c211e","fbAccessToken":"2227470867|2.AQA19SOnrUjqRy-Y.3600.1310454000.0-757629911|lpHIBB-ghCPt73ZlaDtWDmOcro0","type":"c","platform":"a"}
// ####################################
// ####################################

// ####################################
// here's the wcf json service signature
// ####################################

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

// do something


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


// ####################################
// here's the ServiceRequest object define in the json service
// ####################################

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

  }
}


// ####################################
// ####################################
mmdemirbas
  • 8,486
  • 5
  • 44
  • 51
Daniel Nguyen
  • 65
  • 1
  • 4

0 Answers0