使用PB12.6做的WEBSERVICE ,在android studio 2.2.3中使用Ksoap2 3.30进行访问。
测试程序:
pbws端:
string f_get_common_sql_test(string SSQL)
string ls_json ,stype
sailjson ljson,ljson1,ljson_data
ljson = create sailjson
ljson1 = create sailjson
ljson_data= create sailjson
long i
stype="TEST"
if isnull(ssql) or ssql='' then ssql="NULL1"+string(now(),"hh:mm:ss")
ljson_data = ljson.addobject('header')
ljson_data.setattribute( 'account','123456789')
ljson_data.setattribute( 'type', '1')
ljson_data.setattribute( 'pwd', '123456')
ljson_data.setattribute( stype, ssql)
for i=1 to 3
ljson_data = ljson.addarrayitem('data')
ljson_data.setattribute( 'account','123456789')
ljson_data.setattribute( 'type', '1')
ljson_data.setattribute( 'pwd', '123456')
next
ls_json = ljson.getformatjson('')
ls_json=gf_replaceall(ls_json,"c__sailjson","")
return ls_json
发布后在浏览器访问都正常
f_get_common_sql_test
Test
To test the operation using the HTTP POST protocol, click the 'Invoke' button.
Parameter Value
ssql:
Invoke
SOAP 1.1
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.
POST /wm_ws/n_wm_ws.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempurl.org/f_get_common_sql_test"
<?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>
<f_get_common_sql_test xmlns="http://tempurl.org">
<ssql>string</ssql>
</f_get_common_sql_test>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<f_get_common_sql_testResponse xmlns="http://tempurl.org">
<f_get_common_sql_testResult>string</f_get_common_sql_testResult>
</f_get_common_sql_testResponse>
</soap:Body>
</soap:Envelope>
SOAP 1.2
The following is a sample SOAP 1.2 request and response. The placeholders shown need to be replaced with actual values.
POST /wm_ws/n_wm_ws.asmx HTTP/1.1
Host: localhost
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<f_get_common_sql_test xmlns="http://tempurl.org">
<ssql>string</ssql>
</f_get_common_sql_test>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<f_get_common_sql_testResponse xmlns="http://tempurl.org">
<f_get_common_sql_testResult>string</f_get_common_sql_testResult>
</f_get_common_sql_testResponse>
</soap12:Body>
</soap12:Envelope>
HTTP POST
The following is a sample HTTP POST request and response. The placeholders shown need to be replaced with actual values.
POST /wm_ws/n_wm_ws.asmx/f_get_common_sql_test HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length
ssql=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempurl.org">string</string>
android端:
package wm.wmb.pbws;
//wm.wmb.pbws.PbwsTestActivity
import android.content.Context;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.StrictMode;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.textservice.TextServicesManager;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import wm.wmb.R;
public class PbwsTestActivity extends AppCompatActivity {
private String ls_result="";
private SoapObject soapObject;
private String result;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pbws_test);
}
// 执行输入校验
public void getStringSql(View v) throws Exception{
String ls_rtn;
//启动后台异步线程进行连接webService操作,并且根据返回结果在主线程中改变UI
QuerySqlTask querySqlTask = new QuerySqlTask(this);
//启动后台任务
querySqlTask.execute("select part_id,source from part where part_id like 'KC%'");
}
public String getRemoteInfo(String ls_sql) throws Exception{
String WSDL_URI = "http://192.168.1.168/wm_ws/n_wm_ws.asmx?wsdl";//wsdl 的uri ?wsdl
String namespace = "http://tempurl.org/";//namespace
String methodName = "f_get_common_sql_test";//要调用的方法名称
SoapObject request = new SoapObject(namespace, methodName);
String SOAP_ACTION = "http://tempurl.org/f_get_common_sql_test";
// 设置需调用WebService接口需要传入的参数
PropertyInfo pi = new PropertyInfo();
pi.setName("SSQL");
pi.setValue("select part_id,source from part where part_id like 'KC%'");
pi.setType(ls_sql.getClass());
request.addProperty(pi);
//创建SoapSerializationEnvelope 对象,同时指定soap版本号(之前在wsdl中看到的)
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
envelope.bodyOut = request;//由于是发送请求,所以是设置bodyOut
envelope.dotNet = true;//由于是.net开发的webservice,所以这里要设置为true
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransportSE = new HttpTransportSE(WSDL_URI,300000);
httpTransportSE.call(SOAP_ACTION, envelope);//调用SOAP_ACTION
// 获取返回的数据
SoapObject object = (SoapObject) envelope.bodyIn;
// 获取返回的结果
result = object.getProperty(0).toString();
return result;
}
class QuerySqlTask extends AsyncTask<String ,Integer,String> {
private Context context;
QuerySqlTask(Context context) {
this.context = context;
}
/**
* 运行在UI线程中,在调用doInBackground()之前执行
*/
@Override
protected void onPreExecute() {
Toast.makeText(context,"开始执行",Toast.LENGTH_SHORT).show();
}
/**
* 后台运行的方法,可以运行非UI线程,可以执行耗时的方法
*/
@Override
protected String doInBackground(String... params) {
// 查询手机号码(段)信息*/
try {
result = getRemoteInfo(params[0]);
} catch (Exception e) {
e.printStackTrace();
}
//将结果返回给onPostExecute方法
return result;
}
/**
* 运行在ui线程中,在doInBackground()执行完毕后执行
*/
@Override
protected void onPostExecute(String string) {
Toast.makeText(context,"执行完毕",Toast.LENGTH_SHORT).show();
EditText editText=(EditText) findViewById(R.id.edt_pbws_test);
editText.setText(string);
}
/**
* 在publishProgress()被调用以后执行,publishProgress()用于更新进度
*/
//@Override
// protected void onProgressUpdate(Integer... values) {
// tv.setText(""+values[0]);
// }
}
}
执行结果:
以上显示传入的参数都是空值,百度都未扎到能解决的方法,各位大侠救场!!