我的网络服务方法;
[WebMethod]
public DataSet Musteriler(string @Sirket,string @User,string @filtre)
{
using (SqlConnection con = new SqlConnection(connstr))
{
try
{
con.Open();
}
catch (Exception)
{
}
SqlCommand km = con.CreateCommand();
SqlDataAdapter da = new SqlDataAdapter(km);
if (Sirket.Trim().Length == 0)
{
return null;
}
km.CommandText = "select SirketKodu,Versiyon from MV4.dbo.SIRKET with(nolock) where kod=@kod";
km.Parameters.Clear();
km.Parameters.AddWithValue("@kod", @Sirket);
DataTable sdt = new DataTable();
da.Fill(sdt);
string sirketkodu = "master";
if (sdt.Rows.Count>0)
{
sirketkodu = "DB_V" + sdt.Rows[0][1] + "_" + sdt.Rows[0][0];
}
km.Connection.ChangeDatabase(mikrosirketkodu);
km.CommandText = "select cari_kod,cari_unvan1 from XXX with(nolock) where (kod like @kod or unvan1 like @kod or unvan2 like @kod or @kod='')";
km.Parameters.Clear();
km.Parameters.AddWithValue("@kod", @filtre.mysearch());
DataSet ds = new DataSet();
da.SelectCommand = km;
da.Fill(ds);
return ds;
}
}
我的Android kSoap2代码;
public static String serverID ;//xxx=http
String URL = "";
final String METHOD_NAME = "Musteriler";
static String NAMESPACE = "xxxx://abc.com/Service.asmx/";
final String SOAP_ACTION = "xxxx://abc.com/Musteriler";
PropertyInfo property = new PropertyInfo();
sendingString send = new sendingString(temizSirket, temizkullId, musFil);
property.setName("Musteriler");
property.setType(send.getClass());
property.setValue(send);
request.addProperty(property);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.bodyOut = request;
envelope.dotNet = true;
envelope.encodingStyle = SoapSerializationEnvelope.ENC2003;
envelope.xsd = SoapEnvelope.XSD;
envelope.xsi = SoapEnvelope.XSI;
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request);
envelope.addMapping(NAMESPACE, send.getClass().getSimpleName(), sendingString.class);
HttpTransportSE httpTransport = new HttpTransportSE("http://" + serverID);
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope);
response = (SoapObject) envelope.getResponse();
List<String> list = new ArrayList<String>();
for (int i = 1; i < response.getPropertyCount(); i++) {
if (response.getProperty(i).toString().trim() != null) {
SoapObject newDataSet = (SoapObject) response.getProperty(i);
SoapObject tablo = (SoapObject) newDataSet.getProperty(0);
SoapObject icerik = (SoapObject) tablo.getProperty(0);
list.add("Kod:" + icerik.getProperty(0).toString() + "-CariUnvan:" + icerik.getProperty(1).toString());
}else {
list.add("");
}
}
musteriAdapter = new ArrayAdapter<String>(this , R.layout.list_spinner, list);
musteri_sec.this.runOnUiThread(yeni);
} catch (Exception e) {
String a = e.toString();
}
}
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
Call();
}
});
Thread yeni = new Thread(new Runnable() {
@Override
public void run() {
musteriSpinner = (Spinner) findViewById(R.id.spinnerMusteri);
musteriSpinner.setAdapter(musteriAdapter);
}
});
public class sendingString implements KvmSerializable {
private String xSirket,xUser,xfiltre;
public sendingString(String Sirket, String User, String filtre){
super();
this.xSirket = Sirket;
this.xUser = User;
this.xfiltre = filtre;
}
public String getSirket(){
return xSirket;
}
public void setSirket(){
this.xSirket= xSirket;
}
public String getUser(){
return xUser;
}
public void setUser(){
this.xUser= xUser;
}
public String getfiltre(){
return xfiltre;
}
public void setfiltre(){
this.xfiltre= xfiltre;
}
@Override
public Object getProperty(int propertyNumber) {
Object property = null;
switch (propertyNumber) {
case 0:
property = this.xSirket;
break;
case 1:
property = this.xUser;
break;
case 2:
property = this.xfiltre;
break;
default:
break;
}
return property;
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 3;
}
@Override
public void getPropertyInfo(int propertyNumber, Hashtable arg1, PropertyInfo propertyInfo) {
switch (propertyNumber) {
case 0:
propertyInfo.type = PropertyInfo.STRING_CLASS;
propertyInfo.name = "@Sirket";
propertyInfo.setNamespace(NAMESPACE);
break;
case 1:
propertyInfo.type = PropertyInfo.STRING_CLASS;
propertyInfo.name = "@User";
propertyInfo.setNamespace(NAMESPACE);
break;
case 2:
propertyInfo.type = PropertyInfo.STRING_CLASS;
propertyInfo.name = "@filtre";
propertyInfo.setNamespace(NAMESPACE);
break;
default:
break;
}
}
@Override
public void setProperty(int propertyNumber, Object data) {
switch (propertyNumber) {
case 0:
this.xSirket = String.valueOf(data);
break;
case 1:
this.xUser = String.valueOf(data);
break;
case 2:
this.xfiltre = String.valueOf(data);
break;
default:
break;
}
}
}
}
我有一个没有参数的合适连接。但是当我尝试将参数连接起来时,它总是为空。我好几天都找不到问题的解决方案。谢谢你的支持。
编辑:
SoapObject response = null;
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
String temizkullId = kullKod.split("-")[0].substring(4);
EditText sifre = (EditText) findViewById(R.id.editTextSifre);
String sifreText = sifre.getText().toString();
PropertyInfo property1 = new PropertyInfo();
property1.name = "kod";
property1.setName("kod");
property1.setNamespace(NAMESPACE);
property1.setType(PropertyInfo.STRING_CLASS);
property1.setValue(temizkullId);
request.addProperty(property1);
PropertyInfo property2 = new PropertyInfo();
property2.name = "sifre";
property2.setName("sifre");
property2.setNamespace(NAMESPACE);
property2.setType(PropertyInfo.STRING_CLASS);
property2.setValue(sifreText);
request.addProperty(property2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.bodyOut = request;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE("http://" + serverID);
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope);
response = (SoapObject) envelope.getResponse();
boolean ok = (Boolean) response.getProperty(0);
response = (SoapObject) envelope.getResponse();
排队; “SoapFault - faultcode:'soap:Server'faultstring:'服务器无法处理请求.---&gt;字符串引用未设置为String的实例。 参数名称:s'faultactor:'null'详细信息:org.kxml2.kdom.Node@b4dfd350“我收到错误。
网络服务方法:
[WebMethod]
public bool SifreKontrol(string kod, string sifre)
{
using (SqlConnection con = new SqlConnection(connstr))
{
try
{
con.Open();
}
catch (Exception)
{
}
SqlCommand km = con.CreateCommand();
km.CommandText ="select count(*) from MV4.dbo.USERS with (NOLOCK) where kod=@kod and isnull(pasif, 0)=0 and (pass=@pass)";
km.Parameters.Clear();
km.Parameters.AddWithValue("@kod", kod);
km.Parameters.AddWithValue("@pass", sifreleme.Encrypt(sifre, true));
if (km.ExecuteScalar().Tamsayi() > 0)
return true;
else return false;
}
}
请帮助我......
答案 0 :(得分:0)
我解决了这个问题:
[WebMethod]
public bool SifreKontrol(Object kod, Object sifre)
{
using (SqlConnection con = new SqlConnection(connstr))
{...}}
和
PropertyInfo property2 = new PropertyInfo();
property2.name = "sifre";
property2.setName("sifre");
property2.setNamespace(NAMESPACE);
property2.setType(PropertyInfo.OBJECT_TYPE);
property2.setValue(sifreText);
request.addProperty(property2);
答案 1 :(得分:0)
推荐给任何人。点网版4.0及以上版本,提供网络服务准备。非常舒服。