3

我怎样才能WebMethod在我的Java Applet?

EnrollClientC#中调用的方法

我的尝试

    public void enroll(String teste) {
       URL u;
       InputStream is = null;             

       try {
           u = new URL("http://localhost:5154/lb.ashx?pwd=abci/EnrollClient");
           is = u.openStream();
           BufferedReader d = new BufferedReader(new InputStreamReader(is));
       } catch (MalformedURLException mue) {              
               mue.printStackTrace();                 
         } catch (IOException ioe) {             
               ioe.printStackTrace();                
         } finally {
              try {
                    is.close();             
              } catch (IOException ioe) {               
         }
    }   

C# Web 方法

public class lb : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";                        
        strings pwd = context.Request["pwd"].ToString();
        business.Client.lb cli = new business.Client.lb();

        JavaScriptSerializer jss = new JavaScriptSerializer();
        StringBuilder sbRes = new StringBuilder();                        
        jss.Serialize(cli.ReturnJSon(), sbRes);

        context.Response.Write(sbRes.ToString());
    }

    [WebMethod]
    public void EnrollClient()
    {
        string template = string.Empty;
        string client = string.Empty;
        try
        {
            business.Client.lb cli = new business.Client.lb();
            cli.EnrollClient(template, client);                                                
        }
        catch (Exception e)
        {
        }
    }

如果我执行相同的代码但使用代码

u = new URL("http://localhost:5154/lb.ashx?pwd=abci");

它将访问ProcessRequest我的 C# 代码。

4

0 回答 0