我正在使用一个使用ASP.net网络服务的Android应用程序,但我在Android工作室的placeKOT()
方法中得到“服务器无法识别HTTP标头的值”错误。我正在使用Ksoap库来与ASP.net webservice沟通。
网络服务代码
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[WebMethod]
public string placeOrder(string _order)
{
try
{
Database db = DatabaseFactory.CreateDatabase("TransportCon");
DataSet rtnDataSet = new DataSet();
string strQuery = ConnectionClass.placeKOT;
DbCommand dbCommand = db.GetStoredProcCommand(strQuery);
dbCommand.CommandTimeout = 0;
rtnDataSet = db.ExecuteDataSet(dbCommand);
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row;
Dictionary<string, object> row1;
int count = 0;
foreach (DataRow dr in rtnDataSet.Tables[0].Rows)
{
row = new Dictionary<string, object>();
row1 = new Dictionary<string, object>();
foreach (DataColumn col in rtnDataSet.Tables[0].Columns)
{
row.Add(col.ColumnName, dr[col]);
// row.Add(count++, row1);
}
rows.Add(row);
}
rtnDataSet.AcceptChanges();
string json = JsonConvert.SerializeObject(rtnDataSet, Formatting.Indented);
return json;
}
catch (Exception ex)
{
throw ex;
}
}
Android App网络服务电话
private static final String PLACE_ORDER = "http://tempuri.org/placeOrder";
private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String placeOrder = "placeOrder";
private static final String SOAP_ADDRESS = "http://10.0.2.2/WebSite1/Service.asmx";
public boolean placeKOT(String item,ArrayList<Items> items){
try {
JSONObject obj = AddItemsToKotTable(item, items);
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,placeOrder);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
// request.addProperty("_touchCode", touchCode);
//Restaurants selectedRES=(Restaurants)selectedItem;
request.addProperty("_order",obj.toString() );
HttpTransportSE androidHttpTransport = new HttpTransportSE(SOAP_ADDRESS);
androidHttpTransport.debug = true;
String results = null;
try {
androidHttpTransport.call(PLACE_ORDER, envelope);
SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
results = result.toString();
if(results=="true")
return true;
else
return false;
}
catch (Exception e){
return false;
}
}
catch(Exception e) {
return false;
}
}
此行之后
androidHttpTransport.call(PLACE_ORDER, envelope);
它引发了异常并且没有达到Visual Studio中的断点
我还有更多的webmethods传递一个String,它可以解决这个特别的问题吗?