调用.NET Web服务时有问题? [英] Problem when calling .net webservice?
问题描述
我创建了一个样本Android应用程序即调用简单的.NET Web服务,并显示在TextView中,下面是code前景:
i created a sample android app i.e. calling simple .net webservice and displaying in TextView, below are the code prospects:
Web服务code:
web service code:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string MobileApp(string acNum)
{
return "Account number is"+acNum;
}
}
Android应用程序code:
android app code:
import java.io.IOException;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;
import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
public class AccountDetails extends TabActivity {
/** Called when the activity is first created. */
private static final String SOAP_ACTION = "http://tempuri.org/MobileApp";
private static final String METHOD_NAME = "MobileApp";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://localhost:58817/MobService/Service.asmx";
private TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.accountdet);
tv=(TextView)findViewById(R.id.tView);
ServiceCall();
}
public void ServiceCall()
{
try{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
request.addProperty("acNum", "123456");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject)envelope.getResponse();
tv.setText(result.toString());
}
catch (final IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final XmlPullParserException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
此外,我添加以下行到清单文件:
Also i added below lines to the manifest file:
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
<uses-sdk android:minSdkVersion="7" />
但我没有得到的结果在TextView的,所以任何一个plz帮助我。
But i didn't get the result in TextView, so any one plz help me.
@nagaraju。
@nagaraju.
推荐答案
我发现我的错误,这很简单,因为我把用户权限行清单文件中的应用程序标签,但其实,我的投入外使应用程序的标签就是为什么我得到响应。
I found my bug, it is simple, As i put user permission lines in manifest file in the application tag but actually, I've to put outside of the application tag so that's why i'm getting the response.
感谢一个n所有回答我,你的答复还帮助我学习的东西:)
Thanks one n all for replying me, your replies also help me to learn stuff :)
这篇关于调用.NET Web服务时有问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!