HTML网页调用Web Service的方法

正在准备一个云盘环境,验证一些细节,为了测试方便,我直接用html调用WebService查看是否正确返回结果。相信很多朋友做过这种简单的事情,由于不熟悉html写法加上自己思维僵化走了点弯路,整理下来给自己备忘。

WebService

@GET
@Path("yyy")
    @Produces(MediaType.APPLICATION_OCTET_STREAM)
    public File getSomthing(
            @QueryParam("sthId1") String bucketName,
            @QueryParam("sthId2") String objectName
    ) {

HTML方式
参见:http://msdn.microsoft.com/en-us/library/45fez2a8%28v=vs.80%29.aspx

<form method=POST action='http://localhost:8080/xxx/yyy'>
       <input type="text" size="5" name='sthId1'\"></td>
       <input type="text" size="5" name='sthId2'\"></td>
       <input type=submit value="Try"> </td>
   </form>


后边的代码未验证,记录备忘,参见:
http://www.codeproject.com/Articles/14610/Calling-Web-Services-from-HTML-Pages-using-JavaScr

调用HelloWorld,无参数

<html>
  <head>
   <title>Hello World</title>
    <script language="JavaScript">
     var iCallID;
     function InitializeService(){
      service.useService(http://localhost:1394/MyWebService.asmx?wsdl, 
	"HelloWorldService");
      service.HelloWorldService.callService("HelloWorld");
     }
     function ShowResult(){
      alert(event.result.value);
     }
    </script>
   </head>
  <body onload="InitializeService()" id="service" 
	style="behavior:url(webservice.htc)" onresult="ShowResult()"> </body>
 </html> 

调用GetAge,带三个参数

<html>
  <head>
   <title>UseSwap</title>
    <script language="JavaScript">
     function InitializeService(){
      service.useService(http://localhost:1394/MyWebService.asmx?wsdl, 
	"GetAgeService");
     }
     var StrYear, StrMonth, StrDay;
     function GetAge(){
      StrYear = document.DemoForm.StringYear.value;
      StrMonth = document.DemoForm.StringMonth.value;
      StrDay = document.DemoForm.StringDay.value;
      service.GetAgeService.callService("GetAge", StrYear, StrMonth, StrDay);
     }
     function ShowResult(){
    alert(event.result.value);
      }
     </script>
    </head>
     <body onload="InitializeService()" id="service" 
	style="behavior:url(webservice.htc)" onresult="ShowResult()">
      <form name="DemoForm">
       Year : <input type="text" name="StringYear"/>
       Month : <input type="text" name="StringMonth"/>
       Day : <input type="text" name="StringDay"/>
       <button onclick="GetAge()">Get Age</button>
      </form>
     </body>
 </html>

返回缓存值调用

<html>
  <head>
   <meta http-equiv="refresh" content="2" />
   <title>Get Date Time</title>
   <script language="JavaScript">
    var iCallID;
    function InitializeService(){
     service.useService(http://localhost:1394/MyWebService.asmx?wsdl, 
	"GetDateTimeService");
     service.GetDateTimeService.callService("GetDateTime");
    }
    function ShowResult(){
     alert(event.result.value);
    }
   </script>
  </head>
  <body onload="InitializeService()" id="service" 
	style="behavior:url(webservice.htc)" onresult="ShowResult()">
  </body>
 </html>




转载于:https://my.oschina.net/quanzl/blog/212203

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值