2013-02-20 3 views
0

안드로이드에서 WCF 메서드를 호출하려고 시도하면 androidHttpTransport.call (...) 에서 멈추고 잠시 후 서버에 연결하지 못했기 때문에 시간 초과가 발생합니다.안드로이드가 WCF 서버에 연결하지 못했습니다.

내 안드로이드 코드 :

public class MainActivity extends Activity { 
private static final String NAMESPACE = "http://try1.com/"; 
private static final String METHOD_NAME = "ObtainAnswerToQuestion"; 
private static final String SOAP_ACTION = "http://bcaa.com/IEightBall/ObtainAnswerToQuestion"; 
private static final String URL = "http://10.0.2.2:8080/MagicEightBallService"; 
Button submit; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    submit = (Button)this.findViewById(R.id.submit); 
    submit.setOnClickListener(new Button.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);      
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);     
      envelope.dotNet = true; 
      PropertyInfo info = new PropertyInfo(); 
      info.setName("Question"); 
      info.setType("Bylawme".getClass()); 
      info.setValue("BB2233asdsa"); 
      request.addProperty(info); 
      envelope.setOutputSoapObject(request); 
      new LongProcess().execute(envelope); 
     } 
    }); 
} 
private class LongProcess extends AsyncTask<Object, Void, Boolean> { 

     @Override 
     protected Boolean doInBackground(Object... param) { 
      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,30000); 
      SoapSerializationEnvelope envelope = (SoapSerializationEnvelope) param[0]; 
      try { 
       androidHttpTransport.call(SOAP_ACTION, envelope); 
       SoapPrimitive result = (SoapPrimitive) envelope.getResponse(); 
       // to get the data 
       String resultData = result.toString(); 
       submit.setText(resultData); 
      } catch (Exception ex) { 
       submit.setText(ex.getMessage()); 
      } 
      return true; 
     }  
     @Override 
     protected void onPostExecute(Boolean result) { 
     } 
     @Override 
     protected void onPreExecute() { 
     } 
     @Override 
     protected void onProgressUpdate(Void... values) { 
     } 
    } 
@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.activity_main, menu); 
    return true; 
} 
    } 

서버 WSDL : 어떤 도움이 크게 감사합니다

<?xml version="1.0" encoding="UTF-8"?> 
     -<wsdl:definitions name="MagicEightBallService"     xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:i0="http://try1.com" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://tempuri.org/"> 
    <wsdl:import location="http://localhost:8080/MagicEightBallService?wsdl=wsdl0" namespace="http://try1.com"/> 
    <wsdl:types/> 
    -<wsdl:binding type="i0:IEightBall" name="BasicHttpBinding_IEightBall"> 
     <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> 
     -<wsdl:operation name="ObtainAnswerToQuestion"> 
      <soap:operation style="document" soapAction="http://try1.com/IEightBall/ObtainAnswerToQuestion"/> 
      -<wsdl:input> 
       <soap:body use="literal"/> 
      </wsdl:input> 
      -<wsdl:output> 
       <soap:body use="literal"/> 
      </wsdl:output> 
     </wsdl:operation> 
     </wsdl:binding> 
    -<wsdl:service name="MagicEightBallService"> 
     -<wsdl:port name="BasicHttpBinding_IEightBall" binding="tns:BasicHttpBinding_IEightBall"> 
      <soap:address location="http://localhost:8080/MagicEightBallService"/> 
     </wsdl:port> 
     </wsdl:service> 
    </wsdl:definitions> 

아래는 코드입니다.

+0

호출이 WCF 서비스로 전달 되나요? 클라이언트를 실행중인 시스템에서 서비스에 액세스 할 수 있습니까? 서비스는 어떻게 호스팅됩니까? – Jocke

답변

0

이 문제가 해결되었습니다.

(1) (... 지금을 찾을 수 없습니다)이 포럼에 다른 질문에서이 솔루션을 찾을 수 :

require to kill a connection when not in use, by adding in the following code 

    System.setProperty("http.keepAlive", "false"); 

에 의해 살아 현재 연결을 유지 등이 그것 때문에이 문제였다

androidHttpTransport.call(...): 
     androidHttpTransport.getServiceConnection().setRequestProperty("Connection","Keep-Alive"); 

(2) LoopProcess 스레드에 answer.setText(...) 전화를 안 직전 라인. 따라서 값을 설정하기 위해 값을 주 스레드로 되돌려 보내면됩니다.

그리고 비올라가 결국 작동합니다!

관련 문제