Пожалуйста, если кто-нибудь есть опыт в потребляющей службе WCF от андроидая столкнулся вопрос при форматировании сложного объекта мыл в андроиде
формата, который мне нужен
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tem="http://tempuri.org/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://schemas.datacontract.org/2004/07/WebService.Contracts">
<v:Header/>
<v:Body>
<tem:Login>
<tem:request>
<web:UserID>0</web:UserID>
<web:Password>1</web:Password>
<web:UserName>admin</web:UserName>
</tem:request>
</tem:Login>
</v:Body>
</v:Envelope>
Формата порождена моего кода
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<Login xmlns="http://tempuri.org/" id="o0" c:root="1">
<UserID i:type="d:string">0</UserID>
<UserName i:type="d:string">admin</UserName>
<Password i:type="d:string">1</Password>
</Login>
</v:Body>
Мой код следующий
1- LoginRequest Класс
public class LoginRequest extends SoapObject implements KvmSerializable {
private String mUserID;
private String mUserName;
private String mPassword;
public LoginRequest() {
super(AppConstants.NAMESPACE, AppConstants.METHOD_NAME_LOGIN);
}
@Override
public Object getProperty(int index) {
switch (index) {
case 0:
return mUserID;
case 1:
return mUserName;
case 2:
return mPassword;
default:
break;
}
return null;
}
@Override
public int getPropertyCount() {
return 3;
}
@SuppressWarnings("rawtypes")
@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
switch (index) {
case 0:
info.type = PropertyInfo.STRING_CLASS;
info.name = AppConstants.REQUEST_PARAM_USER_ID;
break;
case 1:
info.type = PropertyInfo.STRING_CLASS;
info.name = AppConstants.REQUEST_PARAM_USERNAME;
break;
case 2:
info.type = PropertyInfo.STRING_CLASS;
info.name = AppConstants.REQUEST_PARAM_PASSWORD;
break;
default:
break;
}
}
@Override
public void setProperty(int index, Object value) {
if (value == null)
value = "";
switch (index) {
case 0:
mUserID = value.toString();
break;
case 1:
mUserName = value.toString();
break;
case 2:
mPassword = value.toString();
break;
}
}
}
2- Войти Метод
try {
LoginRequest request = new LoginRequest();
request.setProperty(0, "0");
request.setProperty(1, username);
request.setProperty(2, password);
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.addMapping("http://tempuri.org/", "Login", LoginRequest.class);
envelope.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE("my_service_url");
androidHttpTransport.debug = true;
androidHttpTransport.call("my_service_action", "Login"), envelope);
if (envelope.bodyIn != null) {
//LoginResponse response = (LoginResponse) envelope.bodyIn;
}
System.out.println(androidHttpTransport.requestDump);
System.out.println(androidHttpTransport.responseDump);
} catch (Exception e) {
System.out.println(androidHttpTransport.requestDump);
System.out.println(androidHttpTransport.responseDump);
e.printStackTrace();
}
Добавлено implicitTypes = true для объекта конверта. Это удаляет атрибуты i: type, особенно i: type = "n0: request". Попробуйте, если это не сработает. – mmprog