如何使用此URL来同步时间android

时间:2013-03-23 00:01:01

标签: java android web-services wsdl

我有一个网址,用于将服务器时间同步到我的应用程序, 问题是如何做到的?任何人都可以向我解释在这里做什么感谢我真的很感激。

这是URL = http://server10.instaforex.com:2012/TimeService/TimeService.svc/CurrentTime

这是我的主要活动代码。

public class MainActivity extends Activity {

    Timer timeoutTimer;
    final Random myRandom = new Random();
    GenerateTask genTask = new GenerateTask();
    static String RAN_TEXT = "text";

    class GenerateTask extends TimerTask {
        boolean started = false;
        public void run() {
            if (started) {
                System.out.println("generating");
                final TextView textGenerateNumber = (TextView)findViewById(R.id.generatenumber);
                RAN_TEXT = "";

                for(int k=0;k<7;k++){
                    RAN_TEXT += myRandom.nextInt(10) + " ";
                }
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        textGenerateNumber.setText(RAN_TEXT);
                    }
                });
            }
        }
    }

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

        Button buttonGenerate = (Button)findViewById(R.id.generateme);

        buttonGenerate.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                System.out.println("click");
                if (!genTask.started) {
                    genTask.started=true;
                    timeoutTimer = new Timer();
                    timeoutTimer.scheduleAtFixedRate(genTask, 0, 30000);
                } else {
                    genTask.started=false;
                    timeoutTimer.cancel();
                }
            }
       });  
    }
}

2 个答案:

答案 0 :(得分:0)

您提供的网址会返回XML文件,该文件内部没有任何类似内容的内容,您最好还是要求其他网址或给您这个网址的人员提供解释:

<wsdl:definitions name="TimeService" targetNamespace="TimeService">
<wsdl:types>
<xsd:schema targetNamespace="TimeService/Imports">
<xsd:import schemaLocation="http://server10.instaforex.com:2012/TimeService/TimeService.svc?xsd=xsd0" namespace="TimeService"/>
<xsd:import schemaLocation="http://server10.instaforex.com:2012/TimeService/TimeService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
</xsd:schema></wsdl:types><wsdl:message name="ITimeService_GetCurrentDateTime_InputMessage"><wsdl:part name="parameters" element="tns:GetCurrentDateTime"/>
</wsdl:message><wsdl:message name="ITimeService_GetCurrentDateTime_OutputMessage">
<wsdl:part name="parameters" element="tns:GetCurrentDateTimeResponse"/>
</wsdl:message><wsdl:portType name="ITimeService">
<wsdl:operation name="GetCurrentDateTime">
<wsdl:input wsaw:Action="TimeService/ITimeService/GetCurrentDateTime" message="tns:ITimeService_GetCurrentDateTime_InputMessage"/>
<wsdl:output wsaw:Action="TimeService/ITimeService/GetCurrentDateTimeResponse" message="tns:ITimeService_GetCurrentDateTime_OutputMessage"/>
</wsdl:operation></wsdl:portType><wsdl:binding name="BasicHttpBinding_ITimeService" type="tns:ITimeService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetCurrentDateTime">
<soap:operation soapAction="TimeService/ITimeService/GetCurrentDateTime" style="document"/>
<wsdl:input><soap:body use="literal"/>
</wsdl:input><wsdl:output><soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TimeService">
<wsdl:port name="BasicHttpBinding_ITimeService" binding="tns:BasicHttpBinding_ITimeService">
<soap:address location="http://server10.instaforex.com:2012/TimeService/TimeService.svc/basicHttpBinding"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

答案 1 :(得分:0)

URL是WSDL文件的链接,它描述了如何使用Web服务来获取时间。您需要使用某种工具来生成Web服务以获取时间,例如Apache CXF。但是,正如你所说的Android那样,这将是太重了......