【发布时间】:2017-12-05 14:08:04
【问题描述】:
我在我的 Android 应用程序上使用 Ksoap Api。当我在静态 IP 中使用我的 .net Web 服务时,它可以工作,但是当我从本地 IP 使用我的 Web 服务时,就会发生此错误。
SoapFault - faultcode: 'soap:Client' faultstring: 'Server did not recognize the value of HTTP Header SOAPAction: http://10.77.1.81:83/InsertData.' faultactor: 'null' detail: org.kxml2.kdom.Node@43e7e128.
我的网络服务和设备在同一个网络中。 我的代码是
public class WebService {
private static String NAMESPACE = "http://10.77.1.81:83/";
private static String URL = "http://10.77.1.81:83/Android.asmx";
private static String SOAP_ACTION = "http://10.77.1.81:83/";
public static String InsertData(String name,String work,String position, String webMethName) {
String resTxt = null;
// Create request
SoapObject request = new SoapObject(NAMESPACE, webMethName);
// Property which holds input parameters
PropertyInfo celsiusPI = new PropertyInfo();
// Set Name whcih is in webservice
celsiusPI.setName("name");
// Set Value
celsiusPI.setValue(name);
// Set dataType
celsiusPI.setType(String.class);
// Add the property to request object
request.addProperty(celsiusPI);
PropertyInfo celsiusP2 = new PropertyInfo();
// Set Name whcih is in webservice
celsiusP2.setName("work");
// Set Value
celsiusP2.setValue(work);
// Set dataType
celsiusP2.setType(String.class);
// Add the property to request object
request.addProperty(celsiusP2);
PropertyInfo celsiusP3 = new PropertyInfo();
// Set Name whcih is in webservice
celsiusP3.setName("position");
// Set Value
celsiusP3.setValue(position);
// Set dataType
celsiusP3.setType(String.class);
// Add the property to request object
request.addProperty(celsiusP3);
// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
// Invole web service
androidHttpTransport.call(SOAP_ACTION+webMethName, envelope);
// Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
// Assign it to fahren static variable
resTxt = response.toString();
} catch (Exception e) {
resTxt =e.getMessage();
}
return resTxt;
}
【问题讨论】:
-
我发现应用程序将空变量发送到 Web 服务的错误。
标签: android web-services soap android-ksoap2