我有一些在iphone中工作的代码,我想在android中制作相同的应用程序。 我必须使用php webservice。使用肥皂库。 我想使用以下webservice http://www.medihand.org/freechoicedrivers/soap/members.php
这是wsdl代码
- - - - - - - - - - - -
我使用的是我放在这里的安卓代码
public class start extends Activity {
private static final String SOAP_ACTION =“urn:members#syncMemberDetails”;
private static final String METHOD_NAME = "syncMemberDetails";
private static final String NAMESPACE = "http://schemas.xmlsoap.org/wsdl/";
// !!!!! IMPORTANT!!!!! THE URL OF THE CoLDFUSION WEBSERVER NOT LOCALHOST BECAUSE LOCALHOST IS THE ANDROID EMULATOR !!!!!
private static final String URL = "http://www.medihand.org/freechoicedrivers/soap/members.php";
//String sample[] ={"milan","pratik"};
TextView tv;
String s="";
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
/* s = " <?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
"<SOAP-ENV:Envelope\n"+
" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\n"+
" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n"+
" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\n"+
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"+
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"+
" <SOAP-ENV:Body>\n"+
" <syncMemberDetails>\n"+
" <values xsi:type=\"xsd:Array\">\n"+
" <item>\n"+
" <username xsi:type=\"xsd:string\">test</username>\n"+
" <password xsi:type=\"xsd:string\">test</password>\n"+
" <dates xsi:type=\"xsd:Array\">\n"+
" <item>\n"+
" <year xsi:type=\"xsd:int\">2010</year>\n"+
" <month xsi:type=\"xsd:int\">12</month>\n"+
" <day xsi:type=\"xsd:int\">%30</day>\n"+
" <sync xsi:type=\"xsd:int\">(null)</sync>\n"+
" <times xsi:type=\"xsd:Array\">\n"+
" <item>\n"+
" <start xsi:type=\"xsd:int\">0</start>\n"+
" <finish xsi:type=\"xsd:int\">0</finish>\n"+
" <sync xsi:type=\"xsd:int\">0</sync>\n"+
" <timestamp xsi:type=\"xsd:date\">2010-11-10 18:07:44 GMT</timestamp>\n"+
" </item>\n"+
" </times>\n"+
" </item>\n"+
" <item>\n"+
" <year xsi:type=\"xsd:int\">2010</year>"+
" <month xsi:type=\"xsd:int\">12</month>"+
" <day xsi:type=\"xsd:int\">21</day>"+
" <sync xsi:type=\"xsd:int\">0</sync>"+
" <times xsi:type=\"xsd:Array\">"+
" </times>"+
" </item>"+
" </dates>\n"+
" </item>\n"+
" </values>\n"+
" </syncMemberDetails>\n"+
" </SOAP-ENV:Body>\n"+
"</SOAP-ENV:Envelope>";*/
tv = (TextView) findViewById(R.id.title);
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("?????", "array value");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(Request);
AndroidHttpTransport aht = new AndroidHttpTransport (URL);
try {
aht.call(SOAP_ACTION, envelope);
SoapPrimitive resultstring = (SoapPrimitive) envelope.getResponse();
Toast.makeText(this, String.valueOf(resultstring), 5000).show();
} catch(Exception E) {
tv.setText("ERROR:" + E.getClass().getName() + ": " + E.getMessage());
}
} }
我要写的是request.addProperty(????,“value”)
在dotnew网络服务中我用标签在哪里?这里....所以任何人都知道 请告诉我如何访问这个php webservice
我还把已经运行的iphone代码
答案 0 :(得分:2)
使用此代码和相应的更改(包括ksoap库)
String url="http://192.168.1.163/webservice/test.php";
String namespace="http://tempuri.org";
String method="getuser";
SoapObject request=new SoapObject(namespace,method);
request.addProperty("u","admin"); ***//paraemeter of method(u is php method parametr)***
request.addProperty("i","icare"); **/*/paraemeter of method***
SoapSerializationEnvelope soapEnvelope=new SoapSerializationEnvelope(SoapEnvelope.VER10);
soapEnvelope.setOutputSoapObject(request);
AndroidHttpTransport ahi=new AndroidHttpTransport(url);
try
{
ahi.call(soapaction,soapEnvelope);
SoapPrimitive response=(SoapPrimitive)soapEnvelope.getResponse();
}
catch(Exception e)
{
e.printStackTrace();
}