wince与WCF的结合应用(VS2008 VB.Net)

来源:互联网 发布:校园网络认证管理系统 编辑:程序博客网 时间:2024/05/17 05:58

1、安装WM SDK、安装NETCFv35PowerToys(需要用到里面的命令行工具以生成Wince项目所需要的wcf类库)

2、创建解决方案,项目一WINCE程序,项目二WCF服务应用程序(IIS的)

3、WCF类库的生成方法

NetCFSvcUtil.exe http://localhost:23693/Service1.svc?wsdl  /language:VB  /out:WCEWCF.vb  /cfClientBase:CFClientBase.vb

4、部署WInce程序到WM模拟器,其中的终结点地址要替换,不能是Localhost。因为程序已经在模拟器中运行,不是在本机了。

[替换代码一:使用默认的绑定]

Function CreateClientProxy() As Service1Client
        Dim binding As ServiceModel.Channels.Binding = Service1Client.CreateDefaultBinding
        Dim remoteAddress As String = Service1Client.EndpointAddress.Uri.ToString   '原终结点地址
        remoteAddress = ReadXML("IIServer")                        '替换为新的终结点地址
        Dim endpoint As EndpointAddress = New EndpointAddress(remoteAddress)
        Dim client As Service1Client = New Service1Client(binding, endpoint)
        Return client
End Function

[替换代码二:自定义绑定]

Public Function CreateClientProxy() As Service1Client

        Dim binding As New ServiceModel.BasicHttpBinding

        binding.MaxReceivedMessageSize = 2147483647

        binding.MaxBufferPoolSize = 2147483647

        binding.MaxBufferSize = 2147483647

        Dim remoteAddress As String = Service1Client.EndpointAddress.Uri.ToString

        remoteAddress = ReadXML("WCFURL")

        Dim endpoint As EndpointAddress = New EndpointAddress(remoteAddress)

        Dim client As Service1Client = New Service1Client(binding, endpoint)

        Return client

End Function

5、部署WCF程序时,若服务器已经安装过Net3.5。最好运行几个命令如下:

aspnet_regiis -i                     //安装aspnet到IIS

ServiceModelReg.exe //x            //注册WCF组件

ServiceModelReg.exe /s:W3SVC         //安装WEB主机脚本映射,其中W3SVC可替换

最后重启IIS。

运行后若发生 Error: Failed to access IIS metabase错误,则运行:

aspnet_regiis -ga ASPNET

0 0
原创粉丝点击