我想從Android模擬器調用.NET Web服務,但我得到的連接超時異常。ksoap2連接超時
我試着打電話給我的web服務之前,我叫http://www.w3schools.com/webservices/tempconvert.asmx沒有問題。
所以我假設把我在.NET Web服務上無論是在Android應用程序有些不對勁。
的.NET是
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 Pros : System.Web.Services.WebService {
[WebMethod]
public List<Product> Get(int pageIndex,int pageSize) {
var efUnitOfWork = new EFUnitOfWork();
var productsRepos = new ProductRepository(new EFRepository<Product>(), efUnitOfWork);
return (List<Product>)productsRepos.GetByPage(pageIndex, pageSize);
}
}
和Java是
private static final String METHOD_NAME = "Get";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://10.0.0.2:2807/webservices/webService.asmx";
private static String SOAP_ACTION = NAMESPACE+METHOD_NAME;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("pageIndex", "0");
request.addProperty("pageSize", "10");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result=(SoapObject)envelope.getResponse();
String resultData=result.getProperty(0).toString();
}
catch (Exception e) {
e.printStackTrace();
}
}
我缺少的東西?
我增加了超時和我在的AsyncTask移動電話,但我仍然得到同樣的錯誤。 – StrouMfios
您真的可以連接到設備的服務嗎?在瀏覽器上? –
不,我無法連接。但是我將.net應用程序上傳到生產服務器,並且它可以正常工作。本地主機出現問題。 – StrouMfios