wince web

1,nk增加必须组件

  • SYSGEN_HTTPD (Web Server)
  • SYSGEN_ATL (Active Template Libraries)
  • SYSGEN_SOAPTK_SERVER (SOAP Server)
  • SYSGEN_MSXML_HTTP (XML/HTTP)
  • SYSGEN_CPP_EH_AND_RTTI (Exception Handling and Runtime Type Information)
  • SYSGEN_NETUTILS (ipconfig, ping etc…)
2,创建sdk 的dll

If you have been through the process of creating an ATL/COM object using eMbedded Visual C++ 4.0 the following steps should be familiar to you, there are a couple of differences, and parsing the RGS/IDL to generate the WSDL/WSML files is also different – we will cover this later.

Let’s get started with the process of building the ATL/COM object – note that you will need to have created the underlying operating system and SDK, and installed the SDK on your development machine.

In Visual Studio 2005 (a second instance of VS 2005 if you still have the Platform Builder instance open) create a new Visual C++ project, since we’re building for Windows CE you will need to select a Smart Device project – and of course the type of project we’re creating is an ATL Smart Device Project.

New_ATL_Project

For this example I’ve given my project the name of CE6atlws (CE 6.0, ATL, Web Service), choose an appropriate name for your project, and then click OK.

The next step of the wizard is to choose the platform you are going to be building against, the default option is to build for Pocket PC 2003, you will want to remove that (use the “<” button) and select your custom SDK name (my platform SDK is called XMLWS [see below]).

SDK_1

SDK_2

Once you’ve completed the wizard you will have created a simple ATL project, you now need to add a Simple ATL Object to the project – this is where you will expose your XML Web Services code!.

In Visual Studio 2005, select Project | Add Class – Smart Device, ATL Simple Object – this will launch the ATL Simple Object Wizard – you will need to give your project a Short Name, this will automatically fill out the rest of the C++ and COM information.

Simple_object_0

Note that you will also need to change the threading model of the COM object to Free Threaded, you can either click on the “Options” link on the first page of the ATL Simple Object Wizard or click “Next” which will bring you to the same place.

BTW – if you want to know what the difference is between the different threading models (and why they exist) you might want to take a look at Larry Ostermans Blog post on the subject.

http://blogs.msdn.com/larryosterman/archive/2004/04/28/122240.aspx

Simple_Object

Just hit Finish to complete the wizard – ok, we’re done, the next step is to add our specific methods which will define the XML Web Services interface to our project.

Visual Studio provides a number of different ‘views’ on projects, you’ve probably already seen this with the Platform Builder project which gives you a solution view and a catalog items view of your operating system – in the ATL/COM object project we want to view the project as a set of classes and interfaces, not as a set of discrete source files – so, in Visual Studio, switch to the Class View.

Class_View

For this sample I’m going to expose a function (you could expose multiple functions) that returns the current memory load on the operating system, the function is going to be called GetMemoryLoad and is going to return a LONG value (actually, when you see the code you will notice that the function returns an HRESULT, the LONG return value is passed in as a parameter to the function call).

To add the function, Right Click on the ICE6WebService, and select “Add | Add Method”

Enter the Method Name as GetMemoryLoad, select the parameter type as LONG *, and make sure you mark the parameter as “out” and “retval” – finally, give the parameter a name, I chose m_dwMemoryLoad. (Simple!).

AddMethod

All you need to do now is add the code that implements the GetMemoryLoad function – Note that we added the method to the ICE6WebService (the interface), but we add the implementation of the function to the CCE6WebService class.

To add your implementation of the function, click on the “CCE6WebService” class in the Class View, this will show each of the exposed functions from the class (see below) – now double click on the GetMemoryLoad function – this will open the source file for editing.

CCEWebService

Here’s my implementation of the GetMemoryLoad function – The function actually does very little work, in this case we call the Win32 API GlobalMemoryStatus, which takes a MEMORYSTATUS structure as its input and return type, and return MEMORYSTATUS.dwMemoryLoad from the function.

STDMETHODIMP CCE6WebService::GetMemoryLoad(LONG* m_dwMemoryLoad)

{

MEMORYSTATUS memStatus;

memset(&memStatus,0x00,sizeof(memStatus));

memStatus.dwLength=sizeof(memStatus);

GlobalMemoryStatus(&memStatus);

*m_dwMemoryLoad=memStatus.dwMemoryLoad;

return S_OK;

}

That’s all there is to building the ATL/COM object! – Now onto the interesting part, generating the WSDL/WSML, deploying the ATL/COM object to the device, and consuming the Web Service from a desktop application – we’re nearly done!

3,更改CE6atlws.rgs



HKCR


{


ce6atlws.CE6WebService.1 = s 'CE6WebService Class'


{


CLSID = s '{7181384D-957D-4285-BF96-54DFD201B32C}'


}


ce6atlws.CE6WebService = s 'CE6WebService Class'


{


CLSID = s '{7181384D-957D-4285-BF96-54DFD201B32C}'


CurVer = s 'ce6atlws.CE6WebService.1'


}


NoRemove CLSID


{


ForceRemove {7181384D-957D-4285-BF96-54DFD201B32C} = s 'CE6WebService Class'


{


ProgID = s 'ce6atlws.CE6WebService.1'


VersionIndependentProgID = s 'ce6atlws.CE6WebService'


ForceRemove 'Programmable'


InprocServer32 = s '%MODULE%'


{


val ThreadingModel = s 'Free'


}


val AppID = s '%APPID%'


'TypeLib' = s '{B501EF28-FDC9-4E8B-B1F8-C5C77C48E84F}'


}


}


}

4,生成dll后更改将dll转换wsdl

dos cd C:\WINCE600\PUBLIC\COMMON\OAK\BIN\I386


C:\WINCE600\PUBLIC\COMMON\OAK\BIN\I386>wsdlstb_ce -I CE6WebService -P {7181384D-
957D-4285-BF96-54DFD201B32C} ce6atlws.CE6WebService.1 ce6atlws.dll http://192.16
8.1.115/ce6atlws.wsdl ce6atlws.wsdl


5,将CE6atlws.dll .wsdl .wsml

拷贝到开发板windows www wwwpub下

6,在开发板进dos 注册CE6atlws.dll .

regsvr32.exe \windows\www\wwwpub\CE6atlws.dll



7,应用程序调用dll

Let’s start another instance of Visual Studio 2005, and generate a C# desktop forms based application, add a button to the form, and double click the button, this is where we will add our code to call the XML Web Service.

Since we’re going to be calling the XML Web Service we will want to add a Web Reference to the XML Web Service running on the device – select Project | Add Web Reference

Enter the appropriate IP address and name of your WSDL file, and then click Go

Web_Reference_1

If you’ve done everything right (and what could possibly go wrong!?) you will be rewarded with the Web Reference dialog looking something similar to the following – note that the WSDL has been parsed and the GetMemoryLoad function has been found and displayed (w00t!).

Web_Reference_2

The default Web reference name is “webreference” – I changed this to CE6WebService – to add the Web Reference to your application simply click Add Reference.

Here’s the Button Click code.

private void button1_Click(object sender, EventArgs e)

{

CE6WebService.ce6atlws Foo = new desktop_app.CE6WebService.ce6atlws();

int iMemoryLoad=Foo.GetMemoryLoad();

MessageBox.Show("Memory Load: "+iMemoryLoad.ToString());

}

Here’s the result of running the desktop application – click the button on the form, this calls the Web Service running on our CE 6.0 Device Emulator which then returns its current memory load.

c_sharp_application

We can confirm the current memory load of the actual device by running another remote tool from Platform Builder, in this case the Remote Performance Monitor.

Performance_Monitor

So there we have it… Almost everything you wanted to know about creating XML Web Services in native code to run on Windows Embedded CE 6.0 – there are still a couple of loose ends that need to be sorted out, this includes a breakdown of the ConMan component for CE 6.0, and integrating the ATL/COM object directly into the operating system image so that everything is ready to go at boot time.

Let me know if you have any questions!

大部分是网上找的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值