秀纳

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::
.NET WebService:
 1using System;
 2using System.Web;
 3using System.Web.Services;
 4using System.Web.Services.Protocols;
 5using System.Data;
 6using System.Data.SqlClient;
 7
 8[WebService(Namespace = "http://tempuri.org/")]
 9[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
10public class Service : System.Web.Services.WebService
11{
12    public Service () {
13
14        //如果使用设计的组件,请取消注释以下行 
15        //InitializeComponent(); 
16    }

17   [ WebMethod(Description="Per session Hit Counter",EnableSession=true)]
18    public int SessionHitCounter() {
19       if (Session["HitCounter"== null{
20          Session["HitCounter"= 1;
21       }

22       else {
23          Session["HitCounter"= ((int) Session["HitCounter"]) + 1;
24          }

25       return ((int) Session["HitCounter"]);
26    }

27 
28}
JAVA J2ME Client:
 1package moweb;
 2
 3import javax.microedition.lcdui.*;
 4public class Displayable1 extends Form implements CommandListener,Runnable {
 5    public Displayable1() {
 6        super("Displayable Title");
 7        try {
 8            jbInit();
 9        }

10        catch(Exception e) {
11            e.printStackTrace();
12        }

13    }

14
15    private void jbInit() throws Exception {
16        // Set up this Displayable to listen to command events
17        setCommandListener(this);
18        // add the Exit command
19        addCommand(new Command("退出", Command.EXIT, 1));
20        addCommand(new Command("执行", Command.OK, 2));
21        textField1.setLabel("点击次数");
22        textField1.setPreferredSize(19441);
23        this.append(textField1);
24    }

25
26    public void commandAction(Command command, Displayable displayable) {
27        /** @todo Add command handling code */
28        if (command.getCommandType() == Command.EXIT) {
29            // stop the MIDlet
30            MainForm.quitApp();
31        }

32        if (command.getCommandType() == Command.OK) {
33            // stop the MIDlet
34            t = new Thread(this);
35            t.start();
36        }

37    }

38    public void run()
39    {
40        Integer RetInt;
41        service._setProperty(ServiceSoap_Stub.SESSION_MAINTAIN_PROPERTY,new Boolean(true));
42        try{
43            RetInt =service.sessionHitCounter();
44            textField1.setString(RetInt.toString());
45        }

46        catch (Exception e)
47        {
48            e.printStackTrace();
49        }

50    }

51
52    TextField textField1 = new TextField(""""15, TextField.ANY);
53    private Thread t;
54    ServiceSoap_Stub service = new ServiceSoap_Stub();
55
56}

57

Missing SOAP Body or Envelope 错误解决办法:
打开WTK22/bin/ktoolbar  设置:
Edit->Perferences->Secuirty设置Secuirty Domain为Trusted
posted on 2006-10-18 11:57  秀纳  阅读(435)  评论(0)    收藏  举报