-1
Webサービスでは、クラス(またはオブジェクト)を必要とするアクセスしようとしているメソッド(CheckCredentials)があります。complexType要素へのアクセス(Android ksoap2 WCF)
私はWebサービスのcomplexType要素にアクセスしようとしていますが、私は今混乱しています。私はこのリンクを参考にして助けてくれました:http://seesharpgears.blogspot.co.uk/2010/10/ksoap-android-web-service-tutorial-with.html
ユーザー名とパスワードにaddPropertyを挿入する方法と時期は正確にはわかりません。
ご協力いただければ幸いです。
ここでは、Webサービス
は、Web Seriviceの関連する部分である
<xs:element name="CheckCredentials">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="credentials" nillable="true" type="loginCredentials"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CheckCredentialsResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="CheckCredentialsResult" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="loginCredentials">
<xs:sequence>
<xs:element minOccurs="0" name="_password" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="_username" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
loginCredentials.java
public class loginCredentials implements KvmSerializable {
public String Username;
public String Password;
public loginCredentials(){}
public loginCredentials(String username, String password) {
Username = username;
Password = password;
}
public Object getProperty(int arg0) {
switch (arg0) {
case 0:
return Username;
case 1:
return Password;
}
return null;
}
public int getPropertyCount() {
return 2;
}
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
switch(index) {
case 0:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Username";
break;
case 1:
info.type = PropertyInfo.STRING_CLASS;
info.name = "Password";
break;
default:break;
}
}
public void setProperty(int index, Object value) {
switch(index) {
case 0:
Username = value.toString();
break;
case 1:
Password = value.toString();
break;
default:
break;
}
}
}
.Test4.java
public class Test4 extends Activity {
//private String string = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">';
public class SoapTask extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(Test4.this);
protected void onPreExecute() {
this.dialog.setMessage("Checking in...");
this.dialog.show();
}
@Override
protected Void doInBackground(Void... arg0) {
try{
WebServiceCallExample();
}catch (Exception e){
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void result) {
TextView tv = (TextView) findViewById(R.id.Result);
tv.setText(test_string);
if (this.dialog.isShowing()){
this.dialog.dismiss();
}
}
}
private String test_string;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_test4);
new SoapTask().execute();
}
@SuppressWarnings("deprecation")
public void WebServiceCallExample() {
final String NAMESPACE = "http://tempuri.org/";
final String URL = "http://[IP]/MobileWebService/MobileWebService.MobileService.svc";
final String METHOD_NAME = "CheckCredentials";
final String SOAP_ACTION = "http://tempuri.org/IMobileService/CheckCredentials";
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
loginCredentials L = new loginCredentials();
PropertyInfo pi = new PropertyInfo();
pi.setName("L");
pi.setValue(L);
pi.setType(L.getClass());
Request.addProperty(pi);
// "<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'><s:Header><Action s:mustUnderstand='1' xmlns='http://schemas.microsoft.com/ws/2005/05/addressing/none'>http://tempuri.org/IMobileService/CheckCredentials</Action></s:Header><s:Body><CheckCredentials xmlns='http://tempuri.org/'><credentials xmlns:d4p1='http://schemas.datacontract.org/2004/07/MobileWebService' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'><d4p1:_password>Crisps</d4p1:_password><d4p1:_username>C FAIRS</d4p1:_username></credentials></CheckCredentials></s:Body></s:Envelope>"
/* Set the web service envelope */
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(Request);
envelope.addMapping(NAMESPACE, "loginCredentials", new loginCredentials().getClass());
System.out.println("Request::" + Request.toString());
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
// System.out.println(androidHttpTransport.responseDump);
try{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject sp = (SoapObject) envelope.getResponse();
L.Username = sp.getProperty(0).toString();
L.Password = sp.getProperty(1).toString();
//String
//SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
System.out.println("Response::" + resultsRequestSOAP.toString());
test_string = sp.toString();
}catch (Exception e){
// System.out.println(envelope.getResponse());
e.printStackTrace();
} finally {
System.out.println("Fs1:" + androidHttpTransport.requestDump);
System.out.println("Fs2" + androidHttpTransport.responseDump);
}
}
}
Webサービスにアクセスできません。 –
@K Neeraj Lal:今すぐお試しください。 – Chosen1
まだ運がありません。 –