[英]Android KSOAP2 error to get value
我無法從Web服務中獲取價值。 我一直嘗試,但沒有成功。 我做了與WCF,實體框架一起使用的web服務。 該服務器工作正常。 但是我想聯系並從Android手機獲得價值。
我的Android代碼:
private final String NAMESPACE="http://tempuri.org/"; private final String SOAPACTION="http://tempuri.org/IService/GetValues"; private final String METHODNAME="GetTreatmentValues"; private final String URL="http://localhost:49674/Service.svc";
受保護的void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState); setContentView(R.layout.menu); button1.setOnClickListener(new View.OnClickListener(){@Override
public void onClick(View v){SoapObject request = new SoapObject(NAMESPACE,METHODNAME); request.addProperty("value",1); SoapSerializationEnvelope sp = new SoapSerializationEnvelope(SoapEnvelope.VER11); sp.dotNet=true; sp.setOutputSoapObject(request); HttpTransportSE aht = new HttpTransportSE(URL); aht.debug = true; text2.setText(aht.toString()); //AndroidHttpTransport aht = new AndroidHttpTransport(URL); try { aht.call(SOAPACTION,sp); //I have ERROR! no work. //SoapPrimitive resultstring = (SoapPrimitive)sp.getResponse(); text1.setText("test"); //text2.setText(resultstring.toString()); } catch (Exception e) { // TODO: handle exception text2.setText("hata!"); } } });
我收到錯誤aht.call(SOAPACTION,sp); text1永遠不會設置“測試”,我該怎么辦。 我不知道我想念什么。 謝謝。 (使用Ksoap2.4)
嘗試此示例,或使用此代碼檢查您的代碼
http://www.c-sharpcorner.com/uploadfile/88b6e5/how-to-call-web-service-in-android-using-soap/
希望您能找到解決方案。
我將我的Web服務放入ISS。 我的鏈接是http:// localhost:90 / Service.svc?wsdl在此頁面中,我看到xml代碼
-<wsdl:binding name="BasicHttpBinding_IService" type="tns:IService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
wsdl:operation name="GetTreatmentValues">
<soap:operation style="document"
soapAction="http://tempuri.org/IService/GetTreatmentValues"/>
-<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
-<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
我將此代碼寫入Android應用
private final String NAMESPACE="http://tempuri.org/";
private final String SOAPACTION="http://tempuri.org/GetTreatmentValues";
private final String METHODNAME="GetTreatmentValues";
private final String URL="http://localhost:90/Service.svc?singleWsdl";
但是我總是在這里出錯:( :(
try {
aht.call(SOAPACTION,sp); //I have ERROR! no work.
//SoapPrimitive resultstring = (SoapPrimitive)sp.getResponse();
text1.setText("test");
//text2.setText(resultstring.toString());
} catch (Exception e) {
// TODO: handle exception
text2.setText("hata!");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.