Home > Back-end >  My webservice got ResponseCode: 400 (Bad Request)
My webservice got ResponseCode: 400 (Bad Request)

Time:12-01

I already try to compare, use agent postman and soap testing or everything I could do. But I do not found any error for my Post method. It just I get Bad Request.

Here is the sample SOAP 1.1 request that I need to follow.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Save_Progress xmlns="http://smart-mobile-test.bo/">
      <UserID>string</UserID>
      <isNewInsp>string</isNewInsp>
      <InspID>long</InspID>
      <intcsRevID>int</intcsRevID>
      <numSampleSizes>string</numSampleSizes>
      <InspRevID>long</InspRevID>
      <listInspCi>string</listInspCi>
      <methodName>string</methodName>
      <StartTime>string</StartTime>
      <EndTime>string</EndTime>
    </Save_Progress>
  </soap:Body>
</soap:Envelope>

And the following is what I send:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Save_Progress xmlns="http://smart-mobile-test.bo/" >
      Save_Progress<UserID>1</UserID>
      <isNewInsp>true</isNewInsp>
      <InspID>0</InspID>
      <intcsRevID>10048</intcsRevID>
      <numSampleSizes>2</numSampleSizes>
      <InspRevID>0</InspRevID>
      <listInspCi>[{"CIRevID":"11084","CIID":"277","Check Item No":"1","Check Item Name":"TS-1","Feature!":"","Data Type":"1","Tool":"IM SERIES 2Q-62037","Sample Size!":"0","LSL":"232.80","Target":"233.00","USL":"233.20","LCL":"","CL":"","UCL":"","RLCL!":"","RCL!":"","RUCL!":"","UoM!":"mm","Insp. Rank!":"","Insp. Level!":"","CTQ!":"","Side!":"","Position!":"","Image":"","WI":"","Specification":"233.00","Code":"0","GD&T Symbol!":"","Operation!":""," Tol":"0.20","-Tol":"-0.20","CIRemark3!":"","CIRemark4!":"233.00","CIRemark5!":"","CIRemark6!":"","CIRemark 7!":"","CIRemark 8!":"","Data 1":"","Data 2":"","Result1!":"0","Result2!":"0"},{"CIRevID":"11085","CIID":"278","Check Item No":"2","Check Item Name":"TS-2","Feature!":"","Data Type":"1","Tool":"IM SERIES 2Q-62037","Sample Size!":"0","LSL":"125.85","Target":"126.00","USL":"126.15","LCL":"","CL":"","UCL":"","RLCL!":"","RCL!":"","RUCL!":"","UoM!":"mm","Insp. Rank!":"","Insp. Level!":"","CTQ!":"","Side!":"","Position!":"","Image":"","WI":"","Specification":"126.00","Code":"0","GD&T Symbol!":"","Operation!":""," Tol":"0.15","-Tol":"-0.15","CIRemark3!":"","CIRemark4!":"126.00","CIRemark5!":"","CIRemark6!":"","CIRemark 7!":"","CIRemark 8!":"","Data 1":"","Data 2":"","Result1!":"0","Result2!":"0"},{"CIRevID":"11086","CIID":"279","Check Item No":"3","Check Item Name":"TS-3","Feature!":"","Data Type":"1","Tool":"IM SERIES 2Q-62037","Sample Size!":"0","LSL":"148.65","Target":"148.80","USL":"148.95","LCL":"","CL":"","UCL":"","RLCL!":"","RCL!":"","RUCL!":"","UoM!":"mm","Insp. Rank!":"","Insp. Level!":"","CTQ!":"","Side!":"","Position!":"","Image":"","WI":"","Specification":"148.80","Code":"0","GD&T Symbol!":"","Operation!":""," Tol":"0.15","-Tol":"-0.15","CIRemark3!":"","CIRemark4!":"148.80","CIRemark5!":"","CIRemark6!":"","CIRemark 7!":"","CIRemark 8!":"","Data 1":"","Data 2":"","Result1!":"0","Result2!":"0"},{"CIRevID":"11087","CIID":"280","Check Item No":"4","Check Item Name":"TS-4","Feature!":"","Data Type":"1","Tool":"IM SERIES 2Q-62037","Sample Size!":"0","LSL":"41.20","Target":"41.30","USL":"41.40","LCL":"","CL":"","UCL":"","RLCL!":"","RCL!":"","RUCL!":"","UoM!":"mm","Insp. Rank!":"","Insp. Level!":"","CTQ!":"","Side!":"","Position!":"","Image":"","WI":"","Specification":"41.30","Code":"0","GD&T Symbol!":"","Operation!":""," Tol":"0.10","-Tol":"-0.10","CIRemark3!":"","CIRemark4!":"41.30","CIRemark5!":"","CIRemark6!":"","CIRemark 7!":"","CIRemark 8!":"","Data 1":"","Data 2":"","Result1!":"0","Result2!":"0"},{"CIRevID":"11088","CIID":"281","Check Item No":"5","Check Item Name":"TS-5","Feature!":"","Data Type":"1","Tool":"Micrometer 2Q-32008","Sample Size!":"0","LSL":"1.16","Target":"1.30","USL":"1.44","LCL":"","CL":"","UCL":"","RLCL!":"","RCL!":"","RUCL!":"","UoM!":"mm","Insp. Rank!":"","Insp. Level!":"","CTQ!":"","Side!":"","Position!":"","Image":"","WI":"","Specification":"1.30","Code":"0","GD&T Symbol!":"","Operation!":""," Tol":"0.14","-Tol":"-0.14","CIRemark3!":"","CIRemark4!":"1.30","CIRemark5!":"","CIRemark6!":"","CIRemark 7!":"","CIRemark 8!":"","Data 1":"","Data 2":"","Result1!":"","Result2!":""},{"CIRevID":"11089","CIID":"282","Check Item No":"6","Check Item Name":"Hole-Position","Feature!":"","Data Type":"3","Tool":"Visual","Sample Size!":"0","LSL":"","Target":"","USL":"","LCL":"","CL":"","UCL":"","RLCL!":"","RCL!":"","RUCL!":"","UoM!":"","Insp. Rank!":"","Insp. Level!":"","CTQ!":"","Side!":"","Position!":"","Image":"","WI":"","Specification":"","Code":"0","GD&T Symbol!":"","Operation!":""," Tol":"","-Tol":"","CIRemark3!":"","CIRemark4!":"","CIRemark5!":"Yes","CIRemark6!":"","CIRemark 7!":"","CIRemark 8!":"","Data 1":"","Data 2":"","Result1!":"","Result2!":""},{"CIRevID":"11090","CIID":"283","Check Item No":"7","Check Item Name":"Burr","Feature!":"","Data Type":"3","Tool":"Visual","Sample Size!":"0","LSL":"","Target":"","USL":"","LCL":"","CL":"","UCL":"","RLCL!":"","RCL!":"","RUCL!":"","UoM!":"","Insp. Rank!":"","Insp. Level!":"","CTQ!":"","Side!":"","Position!":"","Image":"","WI":"","Specification":"","Code":"0","GD&T Symbol!":"","Operation!":""," Tol":"","-Tol":"","CIRemark3!":"","CIRemark4!":"","CIRemark5!":"Yes","CIRemark6!":"","CIRemark 7!":"","CIRemark 8!":"","Data 1":"","Data 2":"","Result1!":"","Result2!":""},{"CIRevID":"11091","CIID":"284","Check Item No":"8","Check Item Name":"Solder Resist Position Deviation","Feature!":"","Data Type":"3","Tool":"Visual","Sample Size!":"0","LSL":"","Target":"","USL":"","LCL":"","CL":"","UCL":"","RLCL!":"","RCL!":"","RUCL!":"","UoM!":"","Insp. Rank!":"","Insp. Level!":"","CTQ!":"","Side!":"","Position!":"","Image":"","WI":"","Specification":"","Code":"0","GD&T Symbol!":"","Operation!":""," Tol":"","-Tol":"","CIRemark3!":"","CIRemark4!":"","CIRemark5!":"Yes","CIRemark6!":"","CIRemark 7!":"","CIRemark 8!":"","Data 1":"","Data 2":"","Result1!":"","Result2!":""},{"CIRevID":"11092","CIID":"285","Check Item No":"9","Check Item Name":"Crack","Feature!":"","Data Type":"3","Tool":"Visual","Sample Size!":"0","LSL":"","Target":"","USL":"","LCL":"","CL":"","UCL":"","RLCL!":"","RCL!":"","RUCL!":"","UoM!":"","Insp. Rank!":"","Insp. Level!":"","CTQ!":"","Side!":"","Position!":"","Image":"","WI":"","Specification":"","Code":"0","GD&T Symbol!":"","Operation!":""," Tol":"","-Tol":"","CIRemark3!":"","CIRemark4!":"","CIRemark5!":"Yes","CIRemark6!":"","CIRemark 7!":"","CIRemark 8!":"","Data 1":"","Data 2":"","Result1!":"","Result2!":""},{"CIRevID":"11093","CIID":"286","Check Item No":"10","Check Item Name":"Bent","Feature!":"","Data Type":"3","Tool":"Visual","Sample Size!":"0","LSL":"","Target":"","USL":"","LCL":"","CL":"","UCL":"","RLCL!":"","RCL!":"","RUCL!":"","UoM!":"","Insp. Rank!":"","Insp. Level!":"","CTQ!":"","Side!":"","Position!":"","Image":"","WI":"","Specification":"","Code":"0","GD&T Symbol!":"","Operation!":""," Tol":"","-Tol":"","CIRemark3!":"","CIRemark4!":"","CIRemark5!":"Yes","CIRemark6!":"","CIRemark 7!":"","CIRemark 8!":"","Data 1":"","Data 2":"","Result1!":"","Result2!":""},{"CIRevID":"11094","CIID":"287","Check Item No":"11","Check Item Name":"Dimension","Feature!":"Supplier Outgoing Inspection Data","Data Type":"3","Tool":"Visual","Sample Size!":"0","LSL":"","Target":"","USL":"","LCL":"","CL":"","UCL":"","RLCL!":"","RCL!":"","RUCL!":"","UoM!":"","Insp. Rank!":"","Insp. Level!":"","CTQ!":"","Side!":"","Position!":"","Image":"","WI":"","Specification":"","Code":"0","GD&T Symbol!":"","Operation!":""," Tol":"","-Tol":"","CIRemark3!":"","CIRemark4!":"","CIRemark5!":"Yes","CIRemark6!":"","CIRemark 7!":"","CIRemark 8!":"","Data 1":"","Data 2":"","Result1!":"","Result2!":""}]</listInspCi>
      <methodName>IM SERIES 2Q-62037</methodName>
      <StartTime>2022-11-24 08:41:47.557904</StartTime>
      <EndTime>2022-11-24 08:42:27.753563</EndTime>
      
    </Save_Progress>
  </soap:Body>
</soap:Envelope>

The post method that I send is from flutter. Is there something I miss or are there something you guys can suggest me to do?

For the listInspCi i get from

List<Map<String, dynamic>> inspci = [*list*];
String listInspCI = jsonEncode(inspCI);

CodePudding user response:

After having some thoughts, I managed to figure out a way to avoid Bad Request error. Notice that what I done from Flutter is Map<String, dynamic> need to decode to datatable in C# Webservice Api.

Flutter : What I have done is I do UTF8 Encoding first on <listInspCi> before passing data to webservice.

Map<String, dynamic> inspCI = --some data-- ;
  List<int> EncodedlistInspCI = utf8.encode(json.encode(inspCI));
  String listInspCI = jsonEncode(EncodedlistInspCI);

C# : Then I decode again using something like this.

utf8 = new UTF8Encoding();
int[] intList = JsonConvert.DeserializeObject<int[]>(listInspCi);
Byte[] byteList = Array.ConvertAll<int, byte>(intList, Convert.ToByte);
dtInsp = JsonConvert.DeserializeObject<DataTable>(utf8.GetString(byteList));
  • Related