我在我的Android应用程序中使用基于soap的wbeservice它是一个登录页面,但显示默认命名空间tempuri.org并且WSDL文件中没有提到Soap Action所以我应该使用什么作为webservice在线的soap动作域名不在localhost上。
这是我的WebService代码:
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class WebService {
// Namespace of the Webservice - can be found in WSDL
// private static String NAMESPACE = "http://tempuri.org/";
// Webservice URL - WSDL File location
// private static String URL = "http://namastii.co.in/Service.asmx";
// SOAP Action URI again Namespace + Web method name
// private static String SOAP_ACTION = "http://tempuri.org/GetUserDetails";
private static final String SOAP_ACTION = "http://www.namastii.co.in/Service.asmx?op=GetUserDetails";
private static final String OPERATION_NAME = "GetUserDetails";
private static final String WSDL_TARGET_NAMESPACE = "http://namastii.co.in/";
private static final String SOAP_ADDRESS = "http://namastii.co.in/Service.asmx";
public static boolean invokeLoginWS(String username, String passWD,
String webMethName) {
boolean loginStatus = false;
// Create request
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
// Property which holds input parameters
PropertyInfo userName = new PropertyInfo();
PropertyInfo password = new PropertyInfo();
// Set Username
userName.setName("username");
// Set Value
userName.setValue(username);
// Set dataType
userName.setType(String.class);
// Add the property to request object
request.addProperty(userName);
// Set Password
password.setName("password");
// Set dataType
password.setValue(passWD);
// Set dataType
password.setType(String.class);
// Add the property to request object
request.addProperty(password);
// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(SOAP_ADDRESS);
try {
// Invoke web service
androidHttpTransport.call(SOAP_ACTION + OPERATION_NAME, envelope);
// Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
// Assign it to boolean variable variable
loginStatus = Boolean.parseBoolean(response.toString());
} catch (Exception e) {
// Assign Error Status true in static variable 'errored'
CheckDNLoginActivity.errored = true;
e.printStackTrace();
}
// Return booleam to calling object
return loginStatus;
}
}
答案 0 :(得分:0)
通常默认为 SOAP_ACTION = SOAP_NAMESPACE + SOAP_METHOD
因此,只需将SOAP方法名称附加到SOAP名称空间即可。
对于您的网络服务,
private static final String SOAP_ACTION = "http://tempuri.org/GetUserDetails";
private static final String OPERATION_NAME = "GetUserDetails";
private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ADDRESS = "http://www.namastii.co.in/Service.asmx";