0

私は Android クライアントから使用して安らかな WCF を持っています。Android からサービスを呼び出すと、ここで問題がわかりません。「Request Error (400)」が表示されます。これはサービスコードです

<system.serviceModel>
<services>
  <service name="JooyaSilver.MyCOMWebServices.MyCOMServices" behaviorConfiguration="MyServiceBehavior">
    <endpoint address=""
              binding="webHttpBinding"
              contract="JooyaSilver.MyCOMWebServices.IMyCOMServices"
              behaviorConfiguration="httpBehavior"></endpoint>
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="httpBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true" />
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

[ServiceContract()]
public interface IMyCOMServices
{
    [OperationContract]
    [WebInvoke(Method = "GET", UriTemplate = "TestConnection",
        BodyStyle = WebMessageBodyStyle.WrappedRequest,
        ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json)]
    string TestConnection();

    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "SubmitTrackPoint",
        BodyStyle = WebMessageBodyStyle.WrappedRequest,
        ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json)]
    int SubmitTrackPoint(ServiceData sdata);        

    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "GetMyTasks",
        BodyStyle = WebMessageBodyStyle.WrappedRequest,
        ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json)]
    ServiceData GetMyTasks(ServiceData sdata);        

}   
[DataContract()]
public class ServiceData
{
    [DataMember] public string SData;
    [DataMember] public bool IsActionSucceed;       
}

これはアンドロイドコードです

public static HttpPost getHttpPost(String serviceUril, String methodName) {

    String uri = uriBaseAddress + serviceUril + "/" + methodName;
    HttpPost request = new HttpPost(uri);
    request.setHeader("Accept", "application/json");
    request.setHeader("Content-type", "application/json");
    return request;
}

public static StringEntity getStringEntity(String message) throws UnsupportedEncodingException {
    StringEntity msg = new StringEntity(message);
    msg.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
    msg.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
    return msg;
}

public static JSONStringer getCompleteJsonStringer(String sendingData) {
    JSONStringer requestMsg = null;
    try {
        requestMsg = new JSONStringer().object().key("sdata").object()
                .key("SData").value(sendingData)
                .key("IsActionSucceed").value(true)
                .endObject()
                .endObject();
        Logger.d(requestMsg.toString());
    } catch (JSONException e) {
        Logger.e(e.getMessage());
    }
    return requestMsg;
}
HttpPost request = ServicesHelper.getHttpPost(GeneralServices_URI, "SubmitTrackPoint");
HttpClient httpClient = new DefaultHttpClient();

StringBuilder sb = new StringBuilder();
// some code here for data
JSONStringer requestMsg = ServicesHelper.getCompleteJsonStringer(sb.toString());
StringEntity msg2 = ServicesHelper.getStringEntity(requestMsg.toString());
request.setEntity(msg2);
HttpResponse response = httpClient.execute(request);
int scr = response.getStatusLine().getStatusCode();
4

1 に答える 1

0

サービストレースを有効にした後、サービスのロガーが静的コンストラクターでエラーをスローしたことがわかりました。問題を解決した後、すべてが今大丈夫です

于 2013-01-23T17:36:26.687 に答える