将Android App连接到Asp.net Web服务的超时错误

时间:2019-01-25 15:14:44

标签: android web-services soap

下午好。 我正在尝试将Android应用程序连接到本地.net网络服务,并且向我显示了java.net.SocketTimeoutException。 Web服务可在网络中访问,我可以从所有LAN到达。

这是我第一次在Android中进行编程。 我在Android Studio中使用kso​​ap2库,我想我知道我在做什么(显然不是)。 Web服务将接收这四个参数,并将其插入数据库中。

package com.amcspainfresh.amc_marcaje;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import java.net.URL;

public class MainActivity extends AppCompatActivity {

private EditText tcodbarr,tcalibre,tbultos;

//Informació Webservice

final String NAMESPACE = "http://tempuri.org/";
final String URL = "http://svf-ws.amc.lan/WebSite1/WebService.asmx";
final String METHOD_NAME = "PalletMarcadora";
final String SOAP_ACTION = "http://tempuri.org/PalletMarcadora";


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


}




public void enviarWS (View view){

        tcodbarr=(EditText)findViewById(R.id.tcodbarr);
        tcalibre=(EditText)findViewById(R.id.tcalibre);
        tbultos=(EditText)findViewById(R.id.tbultos);

    final  AlertDialog ad=new AlertDialog.Builder(this).create();

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

      request.addProperty("usuario","usuario");
      request.addProperty("codbarr", tcodbarr.getText().toString());
      request.addProperty("bultos", tbultos.getText().toString());
      request.addProperty("calibre", tcalibre.getText().toString());


    SoapSerializationEnvelope envelope = new 
SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);
        envelope.dotNet = true;

    HttpTransportSE ht = new HttpTransportSE(URL,3000000);
    try {
        ht.call(SOAP_ACTION, envelope);
        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
        String resultado=response.toString();
        Log.i("Resultado: ",resultado);
    }
    catch (Exception e)
    {
        e.printStackTrace();
        ad.setTitle("Errores");
        ad.setMessage(e.toString());
        ad.show();
    }

}

}

这是Web服务的WSDL:

<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://tempuri.org/">
            <wsdl:types>
            <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
            <s:element name="PalletMarcadora">
            <s:complexType>
            <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="usuario" type="s:string"/>
            <s:element minOccurs="0" maxOccurs="1" name="codbarr" type="s:string"/>
            <s:element minOccurs="1" maxOccurs="1" name="bultos" type="s:decimal"/>
            <s:element minOccurs="0" maxOccurs="1" name="calibre" type="s:string"/>
            </s:sequence>
            </s:complexType>
            </s:element>
            <s:element name="PalletMarcadoraResponse">
            <s:complexType>
            <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="PalletMarcadoraResult" type="s:string"/>
            </s:sequence>
            </s:complexType>
            </s:element>
            <s:element name="LoginInformix">
            <s:complexType>
            <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="usuario" type="s:string"/>
            <s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
            </s:sequence>
            </s:complexType>
            </s:element>
            <s:element name="LoginInformixResponse">
            <s:complexType>
            <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="LoginInformixResult" type="s:string"/>
            </s:sequence>
            </s:complexType>
            </s:element>
            </s:schema>
            </wsdl:types>
            <wsdl:message name="PalletMarcadoraSoapIn">
            <wsdl:part name="parameters" element="tns:PalletMarcadora"/>
            </wsdl:message>
            <wsdl:message name="PalletMarcadoraSoapOut">
            <wsdl:part name="parameters" element="tns:PalletMarcadoraResponse"/>
            </wsdl:message>
            <wsdl:message name="LoginInformixSoapIn">
            <wsdl:part name="parameters" element="tns:LoginInformix"/>
            </wsdl:message>
            <wsdl:message name="LoginInformixSoapOut">
            <wsdl:part name="parameters" element="tns:LoginInformixResponse"/>
            </wsdl:message>
            <wsdl:portType name="WebServiceSoap">
            <wsdl:operation name="PalletMarcadora">
            <wsdl:input message="tns:PalletMarcadoraSoapIn"/>
            <wsdl:output message="tns:PalletMarcadoraSoapOut"/>
            </wsdl:operation>
            <wsdl:operation name="LoginInformix">
            <wsdl:input message="tns:LoginInformixSoapIn"/>
            <wsdl:output message="tns:LoginInformixSoapOut"/>
            </wsdl:operation>
            </wsdl:portType>
            <wsdl:binding name="WebServiceSoap" type="tns:WebServiceSoap">
            <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
            <wsdl:operation name="PalletMarcadora">
            <soap:operation soapAction="http://tempuri.org/PalletMarcadora" style="document"/>
            <wsdl:input>
            <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
            <soap:body use="literal"/>
            </wsdl:output>
            </wsdl:operation>
            <wsdl:operation name="LoginInformix">
            <soap:operation soapAction="http://tempuri.org/LoginInformix" style="document"/>
            <wsdl:input>
            <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
            <soap:body use="literal"/>
            </wsdl:output>
            </wsdl:operation>
            </wsdl:binding>
            <wsdl:binding name="WebServiceSoap12" type="tns:WebServiceSoap">
            <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
            <wsdl:operation name="PalletMarcadora">
            <soap12:operation soapAction="http://tempuri.org/PalletMarcadora" style="document"/>
            <wsdl:input>
            <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
            <soap12:body use="literal"/>
            </wsdl:output>
            </wsdl:operation>
            <wsdl:operation name="LoginInformix">
            <soap12:operation soapAction="http://tempuri.org/LoginInformix" style="document"/>
            <wsdl:input>
            <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
            <soap12:body use="literal"/>
            </wsdl:output>
            </wsdl:operation>
            </wsdl:binding>
            <wsdl:service name="WebService">
            <wsdl:port name="WebServiceSoap" binding="tns:WebServiceSoap">
            <soap:address location="http://svf-ws.amc.lan/WebSite1/WebService.asmx"/>
            </wsdl:port>
            <wsdl:port name="WebServiceSoap12" binding="tns:WebServiceSoap12">
            <soap12:address location="http://svf-ws.amc.lan/WebSite1/WebService.asmx"/>
            </wsdl:port>
            </wsdl:service>
            </wsdl:definitions>

非常感谢您的帮助!

0 个答案:

没有答案