Проблема в том, что я не могу позвонить в службу wcf json с помощью своего Android-клиента.Я могу вызвать мой сервис wcf json с моим клиентом c # и fiddler с одинаковым параметром запроса.
Каждый раз, когда я пытаюсь вызвать сервис с моим клиентом Android, я получаю эту ошибку: «HTTP / 1.1 405Метод не разрешен. "
Я провел все исследования здесь и в группе разработчиков Google Android, но все еще не могу заставить мой код работать правильно.
Я просто не знаю, чтопроблема больше, если кто-то может, пожалуйста, помогите.
Заранее спасибо.
// ####################################
// 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
}
}
// ####################################
// ####################################