如何在MMIT上使用WMLScript文件(How To Use WMLScript Files With MMIT)

译者有话要说:

我是完全按照此文设置的,但是由于现在大部分手机不支持wml脚本,导致项目中无法使用它。

这真是个悲剧!

 

+++++++++++++++++++++++++++++++++++++++
如何在MMIT上使用WMLScript文件

----------------------------------------------------------------------------
---
文章中的信息适用于:

- 微软移动网络开发工具集(Microsoft Mobile Internet Toolkit (MMIT))
----------------------------------------------------------------------------
---

概要
=======

要完成的任务

- 概要
- 创建一个WMLScript文件
- 创建一个移动Web窗体页面
- 配置系统
- 配置IIS的MIME类型

 

本文将向您演示如何在MMIT页面上使用包含WMLScript的文件(.wmls)。本文中的例子使用一个脚本来计算来自SelectionList上的选项的两个数。


创建WMLScript文件
-------------------------

创建一个名为Math.wmls的文件并加入如下代码:

extern function ComputeNums(func2Call, x, y) { var retVal = 0; if(func2Call == 1) { retVal = Add(x, y); } else if(func2Call == 2) { retVal = Subtract(x, y); } else if(func2Call == 3) { retVal = Multiply(x, y); } else if(func2Call == 4) { retVal = Divide(x, y); } WMLBrowser.setVar("TextBox3", retVal); WMLBrowser.refresh(); } function Add(x, y) { return (x + y); } function Subtract(x, y) { return(x - y); } function Multiply(x, y) { return(x * y); } function Divide(x, y) { return(x / y); } 

 

 

创建一个移动Web窗体页面

-----------------------------

 

使用WML脚本的重点是只有WML客户接收WML脚本。

这可以通过使用DeviceSpecific类创建一个基于WML硬件的过滤器来完成。一旦定义了DeviceSpecific类,一个脚本模板(ScriptTemplate)就可以用来为页面插入WML脚本了。创建一个名为UseScriptFile.aspx的文件和刚刚的脚本在同一目录并加入下面代码来说明如何创建DeviceSpecific过滤器:

<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <%@ Page language="c#" Inherits="System.Web.UI.MobileControls.MobilePage" %> <mobile:Form id=Form1 runat="server"> <mobile:SelectionList ID="computeType" Runat=server SelectType=Radio Title="Operation"> <Item Text="Add" Value="1" Selected=True></Item> <Item Text="Subtract" Value="2"></Item> <Item Text="Multiply" Value="3"></Item> <Item Text="Divide" Value="4"></Item> </mobile:SelectionList> <mobile:TextBox id=TextBox1 runat="server" Text="2"></mobile:TextBox> <mobile:TextBox id=TextBox2 runat="server" Text="3"></mobile:TextBox> <mobile:TextBox id=TextBox3 runat="server" Text=""></mobile:TextBox> <DeviceSpecific> <Choice Filter="isWML11"> <scriptTemplate> <do type="accept" label="Compute"> <go href="Math.wmls#ComputeNums($(computeType), $(TextBox1), $(TextBox2))" mce_href="Math.wmls#ComputeNums($(computeType), $(TextBox1)," /> </do> </scriptTemplate> </Choice> </DeviceSpecific> </mobile:Form> 

 

注意:上面的示例代码并不能在非WML设备上正常处理。这需要使用一个移动命令控件(Command)并为其创建一个postback事件,或者创建一个客户端脚本给非WML设备来使用脚本模板(ScriptTemplate)。



配置系统
--------------------
在过滤器中使用DeviceSpecific类时,设备过滤器(DeviceFilters)部分需要在web.config文件进行配置。下面是过滤WML设备的例子。在相同目录下创建一个名为web.config的文件并加入如下代码:

<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.web> <deviceFilters> <filter name="isWML11" compare="PreferredRenderingType" argument="wml11" /> </deviceFilters> </system.web> </configuration>



配额IIS MIME类型
---------------------------

 

你需要在IIS上配置WML脚本的MIME类型(资源的媒体类型)才能够成功的使用WML脚本。可以按照如下步骤完成:

 

1、在Web服务器上打开网络服务管理器。

2、右键点击机器名称并点击“属性”。

3、在计算机属性对话框的IIS上点击“编辑”按钮找到“计算机MIME映射”("Computer MIME Map")部分。


4、在“文件类型”的对话框,点击“新类型...”按钮。

5、在“文件类型”对话框,输入“.wmls”在“关联扩展”("Associated extension")文本框。在"Content Type (MIME)"对话框输入"text/vnd.wap.wmlscript"。


6、点击“确定”按钮关闭“文件类型”("File Type")对话框。


7、点击“确定”按钮关闭“文件类型”("File Types")对话框。

8、点击“确定”按钮关闭 计算机属性对话框。


9、重启IIS.


+++++++++++++++++++++++++++++++++++++++

 

原文:http://www.dotnet247.com/247reference/msgs/20/103177.aspx

+++++++++++++++++++++++++++++++++++++++
HOW TO: How To Use WMLScript Files With MMIT [idea]

----------------------------------------------------------------------------
---
The information in this article applies to:

- Microsoft Mobile Internet Toolkit (MMIT)
----------------------------------------------------------------------------
---

SUMMARY
=======

IN THIS TASK

- SUMMARY
- Create The WMLScript File
- Create A Mobile Web Form Page
- Configure the System
- Configure the IIS MIME Type

This article will demonstrate how to include WMLScript files (.wmls) for use
within Microsoft Mobile Internet Toolkit (MMIT) pages. The example in this
article will use a script which will compute two numbers based on the
selection
of a SelectionList.

Create The WMLScript File
-------------------------

Create a file named Math.wmls and add the following code:

extern function ComputeNums(func2Call, x, y)
{
    var retVal = 0;

    if(func2Call == 1)
    {    
        retVal = Add(x, y);
    }
    else if(func2Call == 2)
    {
        retVal = Subtract(x, y);
    }
    else if(func2Call == 3)
    {
        retVal = Multiply(x, y);
    }
    else if(func2Call == 4)
    
    {
        retVal = Divide(x, y);
    }

    WMLBrowser.setVar("TextBox3", retVal);
    WMLBrowser.refresh();
}

function Add(x, y)
{    
    return (x + y);
}

function Subtract(x, y)
{    
    return(x - y);
}

function Multiply(x, y)
{    
    return(x * y);
}

function Divide(x, y)
{    
    return(x / y);
}

Create A Mobile Web Form Page
-----------------------------

When working with WML Script it is important that only WML clients receive
the
WML Script. This can be accomplished by using the DeviceSpecific class to
create
a filter for WML based devices. Once the DeviceSpecific class is defined, a
ScriptTemplate can be used to insert WML Script into the page. Create a file
named UseScriptFile.aspx in the directory where the Math.wmls is located
and add
the following code that illustrates how to create a DeviceSpecific filter:

<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<%@ Page language="c#"
Inherits="System.Web.UI.MobileControls.MobilePage" %>

<mobile:Form id=Form1 runat="server">
<mobile:SelectionList ID="computeType" Runat=server SelectType=Radio
Title="Operation">
<Item Text="Add" Value="1" Selected=True></Item>
<Item Text="Subtract" Value="2"></Item>
<Item Text="Multiply" Value="3"></Item>
<Item Text="Divide" Value="4"></Item>    
</mobile:SelectionList>
<mobile:TextBox id=TextBox1 runat="server" Text="2"></mobile:TextBox>
<mobile:TextBox id=TextBox2 runat="server" Text="3"></mobile:TextBox>
<mobile:TextBox id=TextBox3 runat="server" Text=""></mobile:TextBox>

<DeviceSpecific>

<Choice Filter="isWML11">
<scriptTemplate>
<do type="accept" label="Compute">
<go href="Math.wmls#ComputeNums($(computeType), $(TextBox1),
$(TextBox2))" />
</do>
</scriptTemplate>

</Choice>

</DeviceSpecific>

</mobile:Form>

Note: The sample code above does not handle processing for non-WML devices.
This
may require using a mobile Command control and creating a postback event for
that control, or creating client side script for non-WML devices using a
ScriptTemplate.

Configure The System
--------------------

A DeviceFilters section is required in the web.config file when using the
DeviceSpecific class with a filter. Below is a sample of a device filter
for WML
based devices. Create a file named web.config in the directory where the
UseScriptFile.aspx is located and add the following lines of code:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<deviceFilters>
<filter name="isWML11" compare="PreferredRenderingType"
argument="wml11" />
</deviceFilters>
</system.web>
</configuration>

Configure the IIS MIME Type
---------------------------

You will need to configure a WML Script MIME type in Internet Information
Server
(IIS) in order for the WML Script to run successfully. This can be done by
using
the following steps:

1. Open the Internet Services Manager on the web server.

2. Right-click the machine name in the left pane and click "Properties".

3. Click the "Edit" button found in the "Computer MIME Map" section on the
"Internet Information Services" tab of the computer properties dialog.

4. In the "File Types" dialog, click the "New Type..." button.

5. In the "File Type" dialog, enter ".wmls" in the "Associated extension"
textbox. Enter "text/vnd.wap.wmlscript" in the "Content Type (MIME)"
dialog.

6. Click the "OK" button to close the "File Type" dialog.

7. Click the "OK" button to close the "File Types" dialog.

8. Click the "OK" button to close the machine properties dialog.

9. Right-click the machine name in the left pane and click "Restart IIS...".

+++++++++++++++++++++++++++++++++++++++

你可能感兴趣的:(function,server,Microsoft,mobile,internet,textbox)