我是新來的這個android應用程序,所以我開發了一個示例.net web服務應用程序,並將此服務放在另一臺機器IIS服務器中,並從那裏調用到我的系統。但我沒有得到迴應一切看起來不錯,所以我把我的代碼放在skydrive所以請下載我的代碼「Android應用程序和.net服務.rar」從下面的鏈接,並檢查它,並告訴我什麼是錯的,獲取.NET Web服務響應的問題?
[WebService的空間(namespace = 「http://tempuri.org/」:2天我跟那個:(
這是我的代碼...
.NET Web服務代碼掙扎)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] //若要允許使用ASP.NET AJAX從腳本調用此Web服務,請取消註釋以下行: [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 type)
{
return "Type is"+type;
}
}
服務呼叫號碼在蝕:
public void ServiceCall()
{
try{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("type",view1.getText().toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
//@SuppressWarnings("deprecation")
//ndroidHttpTransport androidHttpTransport=new AndroidHttpTransport(URL);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug=true;
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
TextView txtView=(TextView)findViewById(R.id.txtSer);
txtView.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();
}
}
線清單中加入:
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
<uses-sdk android:minSdkVersion="7" />
@nag
除了需要下載和解壓縮rar文件的人外,請告訴我們您看到的是什麼,並在服務器和客戶端上提供適當的代碼部分。 –
看起來你之前問過這個問題:http://stackoverflow.com/questions/6872219/problem-when-calling-net-webservice從上一個問題,它看起來像你有2臺電腦 - 他們是否正確聯網?你可以從另一個ping一個嗎? –
@John兩者都是不同的樣本,但概念是相同的,但我沒有附上任何我的解決方案下載。 – nag