基於IIS的WCF的分布式多層架構開發實現

安卓7+抓包必备:Root后如何把证书塞进系统目录(附权限设置避坑指南) 本文详细解析了在安卓7+ Root环境下将抓包证书部署到系统目录的全流程,包括证书处理、哈希计算、多种部署方案对比及权限设置避坑指南。通过ADB工具和系统目录操作,开发者可有效解决安卓7.0+不信任用户证书的问题,提升抓包分析效率。 阅读详情

 

曾用.NET Remoting,基於IIS,為公司實現過分布式多層架構,客戶端采用Web Browser瀏覽,當時,公司領導告訴我可能會有多臺中間服務器用於系統,又不想每臺電腦的去安裝程序,所以,我最后采用了.NET Remtoing來實現分布式,可直到如今,我也沒有看到有購置多臺中間服務器,哪怕多臺Web服務器的可能性。不過,功能咱是實現了,只要有了機器,俺就用上。先不管他,上博客園來看看,這一看,就看到张逸 和 赵颉兩位牛人的“你知道什么是WCF嗎”的訪談錄,看完之后,對於WCF也就躍躍欲試,於是結合张逸以及博客园另一位牛人artech(都是MVP,羨慕中…..)介紹的內容, 加上本人對於Remoting的開發也有一點功底,於是也就沒有花多少時間,鼓搗出以下這個自己號稱目前最先進的基於IIS的WCF的分布式多層開發架構。

至於WCF的相關知識,咱也不說什么,张逸和Artech這兩位牛人說得已經很是明白了,各位可以通過上面的鏈接去他們的博客上學習啦,不過,感覺有Remoting開發經驗的,對於WCF的相關概念應該不是很難理解。

下面還是用代碼來說明一下(由於這家公司的經理要求使用VB來做,我只好放棄用了近兩年的C#的而改用VB了。還好現在基本上兩種都不會混了,也算是間接的掌握了一門新語言吧,喜歡看C#的朋友就請多擔待,或者留言,本人考盧是否提供一份C#的實現。呵呵:))

1、首先從整體來看這個架構,這個架構的圖示大約如下,共包括了6個專案,大概從專案名稱應該也可看出其主要用途了:


HL.EntityReflect.Osp專案實現是實體對象化。HL.Shared.Osp就是WCF的Contract了,於了Remoting來說,就是一個建議在Server端實現的接口了,其實為了安全性著想,對於WCF,本人也建議使用接口,在Server端實現。HL.Business.Osp就是我們常說的邏輯業務層,它主要負責調用HL.DALSQLServer.Osp真正實現了HL.Shared.Osp的方法。最后兩個HL.Service和HL.Win不用我說,各位也可想到一個是IIS Host的WCF及客戶端的Winform程序了。

上面簡單介紹了各個專案的用途了,下面我們來分步用VB實現:

2、建立實體對象:


Imports System
Imports System.Runtime.Serialization

'/ <summary>
'/ Summary description for EREmployee.
'/ </summary>
<Serializable()> _
<DataContract()> _
Public Class EREmployee
    Public Sub New()
    End Sub

    Private _strbs_no As String
    Private _strbs_name As String

    <DataMember()> _
    Public Property strBS_NO() As String
        Get
            Return Me._strbs_no
        End Get
        Set(ByVal value As String)
            Me._strbs_no = value
        End Set
    End Property


    <DataMember()> _
    Public Property strBS_NAME() As String
        Get
            Return Me._strbs_name
        End Get
        Set(ByVal value As String)
            Me._strbs_name = value
        End Set
    End Property

End Class

這個基於工具也可產生,網上大把。只是要註意的是,要能在WCF中傳遞的實體,必須是可序列化和序列化了的實體,在Remoting中我們需要在類前面冠上<Serializable()> _這種形式的編程即可,同樣在WCF中我們使用的是<DataContract()> _,然后在屬性前面也加上<DataMember()> _聲明。

3、同樣,我們再接著建立一個Contract,引用第二步建立的實體對象。我們使用類似下面的代碼,這里同樣運用了聲明式的編程方式。各位可以自行比較這些代碼跟我們常用的代碼的寫法的差異。


Imports System
Imports System.ServiceModel
Imports HL.EntityReflect.Osp

'/ <summary>
'/ Summary description for IEmployee.
'/ </summary>
<CLSCompliant(False)> _
<ServiceContract()> _
Public Interface IEmployee
    <OperationContract()> _
    Function Query() As EREmployee()

    <OperationContract()> _
    Sub Add(ByVal er As EREmployee)

    <OperationContract()> _
    Sub Modify(ByVal er As EREmployee, ByVal strBS_NO As String, ByVal strBS_Name As String)

    <OperationContract()> _
    Sub Del(ByVal er As EREmployee)

    <OperationContract()> _
    Function fAdd(ByVal intX As Integer, ByVal intY As Integer) As Integer
End Interface



4、這一步實現很關鍵,能否使用WCF成功,這一步至關重要,我們把對應的類繼承於ClientBase,並實現了HL.Shared.Osp,當然真實方法我們在另一個專案中實現,這里算是一個引子吧,權當我曾經好像看過某位牛人(如果沒有記錯應該也是上面張先生寫的一篇文章。關於Remoting的)說的.net下Remoting的欺騙吧。你把他當做欺騙也好,什么也好,只是我需要指明的是這個很重要,代碼如下:


Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports HL.EntityReflect.Osp
Imports HL.Shared.Osp
Imports System.Data.SqlClient


Public Class BLEmployee
    Inherits ClientBase(Of IEmployee)
    Implements IEmployee

    Public Sub New()
        MyBase.New()
    End Sub


    Public Sub New(ByVal endpointConfigurationName As String)
        MyBase.New(endpointConfigurationName)
    End Sub


    Public Sub Add(ByVal er As EREmployee) Implements IEmployee.Add
        Channel.Add(er)
    End Sub


    Public Sub Del(ByVal er As EREmployee) Implements IEmployee.Del
        Channel.Del(er)
    End Sub


    Public Sub Modify(ByVal er As EREmployee, ByVal strBS_NO As String, ByVal strBS_Name As String) Implements IEmployee.Modify
        Channel.Modify(er, strBS_NO, strBS_Name)
    End Sub


    Public Function Query() As EREmployee() Implements IEmployee.Query
        Return Channel.Query()
    End Function



    Public Function fAdd(ByVal intX As Integer, ByVal intY As Integer) As Integer Implements IEmployee.fAdd
        Return Channel.fAdd(intX, intY)
    End Function

End Class


當然,如果我想實現數據庫類型的切換,我以前用Remoting的時候,就在這個類中做手腳,但關於WCF卻感覺無從下手,如果哪位知道,請留言指教,不勝感激。

5、收尾一下4步中遺留的真正實現方法,不多說,直接看代碼:


Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports HL.EntityReflect.Osp
Imports HL.Shared.Osp

Public Class SQLDaoEmployee
    Implements IEmployee

    Public ReadOnly Property strConn() As String
        Get
            Return Configuration.ConfigurationManager.AppSettings("strConnectNorthWind")
        End Get
    End Property


    Public Sub Add(ByVal er As EREmployee) Implements IEmployee.Add
        Dim strSql As String = "Insert Into Employee(BS_NO,BS_NAME) Values(@BS_NO,@BS_NAME)"
        Using Conn As New SqlConnection(strConn)
            Using Comm As New SqlCommand(strSql, Conn)
                Comm.Parameters.Add(New SqlParameter("@BS_NO", SqlDbType.VarChar, 10))
                Comm.Parameters.Add(New SqlParameter("@BS_NAME", SqlDbType.VarChar, 20))
                Comm.Parameters("@BS_NO").Value = er.strBS_NO
                Comm.Parameters("@BS_NAME").Value = er.strBS_NAME
                Conn.Open()
                Comm.ExecuteNonQuery()
                Conn.Close()
            End Using
        End Using
    End Sub


    Public Sub Del(ByVal er As EREmployee) Implements IEmployee.Del
        Dim strSql As String = "Delete from  Employee where BS_NO ='" & er.strBS_NO & "' and BS_NAME='" & er.strBS_NAME & "'"
        Using Conn As New SqlConnection(strConn)
            Using Comm As New SqlCommand(strSql, Conn)
                Conn.Open()
                Comm.ExecuteNonQuery()
                Conn.Close()
            End Using
        End Using
    End Sub


    Public Sub Modify(ByVal er As EREmployee, ByVal strBS_NO As String, ByVal strBS_Name As String) Implements IEmployee.Modify
        Dim strSql As String = "  update  Employee set BS_NO='" & strBS_NO & "', BS_NAME= '" & strBS_Name & _
                               "' where BS_NO ='" & er.strBS_NO & "' and BS_NAME='" & er.strBS_NAME & "'"
        Using Conn As New SqlConnection(strConn)
            Using Comm As New SqlCommand(strSql, Conn)
                Conn.Open()
                Comm.ExecuteNonQuery()
                Conn.Close()
            End Using
        End Using

    End Sub


    Public Function Query() As EREmployee() Implements IEmployee.Query
        Dim lst As New List(Of EREmployee)()
        Dim strSql As String = "Select * From Employee"
        Using Conn As New SqlConnection(strConn)
            Using Comm As New SqlCommand(strSql, Conn)
                Conn.Open()
                Dim Reader As SqlDataReader = Comm.ExecuteReader()
                While Reader.Read()
                    Dim er As New EREmployee()
                    er.strBS_NO = DirectCast(Reader("BS_NO"), String)
                    er.strBS_NAME = DirectCast(Reader("BS_NAME"), String)
                    lst.Add(er)
                End While
                Conn.Close()
            End Using
        End Using
        Return lst.ToArray()
    End Function



    Public Function fAdd(ByVal intX As Integer, ByVal intY As Integer) As Integer Implements IEmployee.fAdd
        Return intX + intY
    End Function


End Class


6、至此我們,可以開始配置,基於IIS的WCF服務端了。請看配置文件


<?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    /Windows/Microsoft.Net/Framework/v2.x/Config 
-->
<configuration>

    <configSections>
      <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
          <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
            <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
            <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
            <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
          </sectionGroup>
        </sectionGroup>
      </sectionGroup>
    </configSections>

  <system.serviceModel>
    <services>
      <service name="HL.DALSQLServer.Osp.SQLDaoEmployee" behaviorConfiguration="ServiceBehavior">
        <!-- Service Endpoints -->
        <endpoint address="" binding="basicHttpBinding" contract="HL.Shared.Osp.IEmployee">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

  <appSettings>
    <add key ="strConnectNorthWind" value ="Data Source=dg;Initial Catalog=Northwind;User ID=sa;Password="/>
  </appSettings>
    <connectionStrings/>

    <system.web>
        <!--
            Set compilation debug="true" to insert debugging 
            symbols into the compiled page. Because this 
            affects performance, set this value to true only 
            during development.

            Visual Basic options:
            Set strict="true" to disallow all data type conversions 
            where data loss can occur. 
            Set explicit="true" to force declaration of all variables.
        -->
        <compilation debug="false" strict="false" explicit="true">

          <assemblies>
            <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          </assemblies>

        </compilation>
        <pages>
          <namespaces>
            <clear />
            <add namespace="System" />
            <add namespace="System.Collections" />
            <add namespace="System.Collections.Specialized" />
            <add namespace="System.Configuration" />
            <add namespace="System.Runtime.Serialization" />
            <add namespace="System.ServiceModel" />
            <add namespace="System.Text" />
            <add namespace="System.Text.RegularExpressions" />
            <add namespace="System.Linq" />
            <add namespace="System.Web" />
            <add namespace="System.Web.Caching" />
            <add namespace="System.Web.SessionState" />
            <add namespace="System.Web.Security" />
            <add namespace="System.Web.Profile" />
            <add namespace="System.Web.UI" />
            <add namespace="System.Web.UI.WebControls" />
            <add namespace="System.Web.UI.WebControls.WebParts" />
            <add namespace="System.Web.UI.HtmlControls" />
          </namespaces>

          <controls>
            <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          </controls>

        </pages>
        <!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        -->
        <authentication mode="Windows" />
        <!--
            The <customErrors> section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically, 
            it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->


      <httpHandlers>
        <remove verb="*" path="*.asmx"/>
        <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
      </httpHandlers>
      <httpModules>
        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </httpModules>


    </system.web>

    <system.codedom>
      <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
                  type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <providerOption name="CompilerVersion" value="v3.5"/>
          <providerOption name="WarnAsError" value="false"/>
        </compiler>
        <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4"
                  type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <providerOption name="CompilerVersion" value="v3.5"/>
          <providerOption name="OptionInfer" value="true"/>
          <providerOption name="WarnAsError" value="false"/>
        </compiler>
      </compilers>
    </system.codedom>

    <system.web.extensions>
      <scripting>
        <webServices>
          <!--
              Uncomment this section to enable the authentication service. Include 
              requireSSL="true" if appropriate. 

          <authenticationService enabled="true" requireSSL = "true|false"/>
          -->
          <!--
              Uncomment these lines to enable the profile service, and to choose the 
              profile properties that can be retrieved and modified in ASP.NET AJAX 
              applications.

           <profileService enabled="true"
                           readAccessProperties="propertyname1,propertyname2"
                           writeAccessProperties="propertyname1,propertyname2" />
          -->
          <!--
              Uncomment this section to enable the role service.

          <roleService enabled="true"/>
          -->
        </webServices>
        <!--
        <scriptResourceHandler enableCompression="true" enableCaching="true" />
        -->
      </scripting>
    </system.web.extensions>
    <!--
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
    <system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <modules>
        <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </modules>
      <handlers>
        <remove name="WebServiceHandlerFactory-Integrated"/>
        <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
             type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
             type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </handlers>
    </system.webServer>


</configuration>
      這個配置文件是 2008 自動生成的,我沒有做更改,其實,你只需要更改的是 < system.serviceModel > 這個 Selection 。當然,在 < appSettings > 塊中需改動你的數據庫連接字串,這個其實,也不需要我提醒嘍。然后新建一個 Svc 文件,該文件指明使用的語言和 Service 的名稱即可,只要一行即可: <% @  ServiceHost Language="VB" Debug="true"Service="HL.DALSQLServer.Osp.SQLDaoEmployee"%>

7、至此,你已經在IIS服務端配置文件憶寫好,剩下就是去的IIS中配置了,這一步,跟平常配置Web程序一樣,沒多大分別。

8、好了,開始寫客戶端程序吧,這個其實很簡單,我也不說什么註意事項了,直接看代碼吧:


Imports HL.EntityReflect.Osp
Imports HL.Business.Osp

Public Class FrmEmployee

    Private strBS_NO As String = Nothing
    Private strBS_NAME As String = Nothing

    Private Sub btnQuery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        Try
            Dim proxy As BLEmployee = New BLEmployee("EmployeeEndpoint")
            Dim dataER As EREmployee() = proxy.Query()
            Me.dgvEmployee.DataSource = dataER
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Sub


    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Try
            Dim proxy As New BLEmployee("EmployeeEndpoint")
            Dim model As New EREmployee()
            model.strBS_NO = tbxBS_NO.Text.Trim()
            model.strBS_NAME = tbxBS_NAME.Text.Trim()
            proxy.Del(model)
            MessageBox.Show("Delete OK, please query again to see result!")
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Sub


    Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Try
            Dim proxy As New BLEmployee("EmployeeEndpoint")
            Dim model As New EREmployee()
            model.strBS_NO = tbxBS_NO.Text.Trim()
            model.strBS_NAME = tbxBS_NAME.Text.Trim()
            proxy.Add(model)
            MessageBox.Show("Add OK, please query again to see result!")
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Sub


    Private Sub btnModify_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnModify.Click
        Try
            Dim proxy As New BLEmployee("EmployeeEndpoint")
            Dim model As New EREmployee()
            model.strBS_NO = strBS_NO
            model.strBS_NAME = strBS_NAME
            proxy.Modify(model, tbxBS_NO.Text.Trim(), tbxBS_NAME.Text.Trim())
            MessageBox.Show("Modify OK, please query again to see result!")
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Sub


    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        Try
            Dim proxy As BLEmployee = New BLEmployee("EmployeeEndpoint")
            Me.tbxBS_NO.Text = String.Format("{0} + {1} ={2}", 1, 2, proxy.fAdd(1, 2))
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Sub


    Private Sub dgvEmployee_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgvEmployee.SelectionChanged
        Try
            strBS_NO = dgvEmployee.Item(0, dgvEmployee.CurrentRow.Index).Value
            strBS_NAME = dgvEmployee.Item(1, dgvEmployee.CurrentRow.Index).Value
            tbxBS_NO.Text = strBS_NO
            tbxBS_NAME.Text = strBS_NAME
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Sub

End Class

配置文件也只需注意<system.serviceModel>塊即可.如下所示:


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel >
    <client>
      <endpoint name="EmployeeEndpoint" address="http://localhost/HL.Service/SvcEmployee.svc" binding="basicHttpBinding" contract="HL.Shared.Osp.IEmployee"/>
    </client>
  </system.serviceModel>
  <system.diagnostics>
    <sources>
      <!-- This section defines the logging configuration for My.Application.Log -->
      <source name="DefaultSource" switchName="DefaultSwitch">
        <listeners>
          <add name="FileLog"/>
          <!-- Uncomment the below section to write to the Application Event Log -->
          <!--<add name="EventLog"/>-->
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="DefaultSwitch" value="Information" />
    </switches>
    <sharedListeners>
      <add name="FileLog"
           type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
           initializeData="FileLogWriter"/>
      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
      <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
    </sharedListeners>
  </system.diagnostics>
</configuration>


9、說明一下,這個演示中的Demo使用的數據庫文件其實跟我去年寫的一篇WinForm下多层架构的实现使用的是同一個,當然,你也可以在下載專案的HL.Win找到,名稱為: Employee.txt,另外,本人的文筆不怎樣,沒法寫出很漂亮的文章出來,這也是為什么好久沒有寫博客的原因,尤其是這種帶有技朮性的文章。所以,說的不對或不好的地方,望諒解,當然,如果這篇文章能給你學習WCF帶來一點啟發或幫助,那麼也就不枉了我寫這篇文章的初衷了。


程序源文件下載

 

Kingna(jinliangliu#163.com)

2008/4/9於博客園

歡迎轉載,轉載請保留以上信息

 

安卓抓包进阶:Root环境下系统证书目录操作全指南 本文详细介绍了在Root环境下操作安卓系统证书目录的全流程,解决安卓7.0及以上系统抓包工具无法正常工作的问题。内容包括Root环境准备、证书导出与哈希计算、系统目录操作及常见问题排查,帮助开发者高效完成HTTPS抓包。 阅读详情

相关推荐

安卓抓包进阶:Root环境下系统证书目录操作指南

本文详细指导了在已Root的安卓设备上,如何将抓包工具的CA证书安装到系统证书目录,以实现对安卓7.0以上版本App的全局HTTPS流量抓取。核心步骤包括使用openssl计算证书哈希值、通过ADB推送并设置文件权限,并提供了操作失败时的疑难解答与安全须知,是安卓安全研究与开发调试的实用进阶指南。

c8d9e0f1的博客 1018

安卓root手机抓包

在最后一步安装证书至系统证书目录可能会报错「adb: error: failed to copy 'XX.0' to '/system/etc/security/cacerts/XX.0': remote couldn't create file: Read-only file system」打开手机设置——密码与安全——系统安全——加密与凭据——信任的凭据——系统栏。可修改设备支持 adb remount 临时挂载为可写:(仅部分设备支持)2️⃣proxyman 同样操作。

m0_58066641的博客 598

C#中如何使用WCF

一、什么是WCF Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分。由 .NET Framework 3.0 开始引入。 从我现在获得的知识,我理解的WCF重点是分布式,比如我们合作可以不把程序都放在一个电脑中,每人一层,同样也可以进行断点调试。 WCF的第一个版本为服务开发提供了许多有用的功能,包括托管、服务实例管理、异步调用、可靠性、事务管理、离线队列调用以及安全性。

憧憬是碎了满地凉凉的宝石 6852

WCF服务寄宿IIS与Windows服务

WCF是Windows平台下程序间通讯的应用程序框架。整合和.net Remoting,WebService,Socket的机制,是用来开发windows平台上分布式开发的最佳选择。wcf程序的运行需要一个宿主ServiceHost,我们可以选用控制台应用程序,也可以选择IIS寄宿,还可以选择windows 服务寄宿。相较与控制台程序,IIS,和Windows服务比较稳定。而且大...

aori3524的博客 225

WCF实现分布式文件上传服务端与客户端开发实例

WCF(Windows Communication Foundation)作为.NET框架中构建服务导向应用程序的核心库,提供了一套全面的API和运行时组件,用于构建分布式、面向服务的应用程序。这一章节将深入探讨WCF服务合同的基础知识,包括服务合同的概念和作用,以及如何通过定义接口来创建这些服务合同。接口是定义服务合同的一种方式,在WCF中,接口使用属性进行修饰。接口中的每个方法都对应一个服务操作,它们通过属性进行标记。这些属性允许开发人员指定操作的名称、行为和数据交换格式等。

weixin_35826166的博客 720

5分钟搞定!用Keil MDK将STM32F103C8T6工程无缝迁移到ZET6开发板

本文详细介绍了如何在Keil MDK环境下快速将STM32F103C8T6工程迁移到ZET6开发板,涵盖硬件差异对比、工程配置调整、外设适配及编译排错等关键步骤,帮助开发者5分钟内完成工程移植,大幅提升开发效率。

weixin_30879169的博客 409

WCF架构入门-用VS2008构建WCF

WCF架构入门-用VS2008构建WCF    根据微软官方的解释,WCF(之前的版本名为“Indigo”)是使用托管代码建立和运行面向服务(Service Oriented)应用程序的统一框架。它使得开发者能够建立一个跨平台的安全、可信赖、事务性的解决方案,且能与已有系统兼容协作。WCF是微软分布式应用程序开发的集大成者,它整合了.Net平台下所有的和分布式系统有关的技术,例如.Net Re

王以山的专栏 9582

防反接电路、防倒灌电路、过流保护和ESP相关知识

1.开关电源给负载供电, 如果负载是电池或者其他感性负载(比如像 电机 有线圈 当电源突然断掉时 会产生感应电动势)时, 当220V断掉的时候,可能会出现 电池反向给开关电源 的 输出端 供电,导致开关电源的一些莫名损坏。2.系统在不同的 输出电压 之间 切换时,会存在高压电压倒灌到低压电压源中。例如:系统 有两个电源供电 比如 一个电池 一个 充电器 充电器的电压一般会高于电池 如果没有防倒灌的电路 可能充电器的电压会直接倒灌给电池 造成电池的损坏。

a_black_的博客 1万+

WCF分布式开发步步为赢(3)WCF服务元数据交换、配置及编程开发

Posted on 2009-03-30 00:10 Frank Xu Lei 阅读(2800) 评论(23)  编辑 收藏 网摘 所属分类: WCF分布式开发步步为赢, SOA and EAI <!--<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"xmlns:dc="ht

微软特邀讲师 老徐FrankXuLei 的专栏 3287

Python 对接钉钉获取员工上一篇日报或周报内容

摘要:本文介绍使用Python对接钉钉API获取员工日报/周报的方法。首先需创建钉钉应用并开通日志权限,获取员工UserID。通过获取AccessToken进行鉴权,调用topapi/report/list查询日志记录,筛选最新日报/周报后,使用topapi/report/details获取详细内容。需注意权限控制、时间范围筛选和模板匹配等问题。文末提供完整代码示例,并建议扩展自动化触发、数据存储等功能。该方法适用于企业自动化获取员工工作日志的场景。

从技术实践立足,从项目管理方法论延伸思考 816

【异常】Nacos 2.x 核心报错:Server check fail (gRPC 端口连不通) 排查指南 Server check fail, please check server xxx-

Nacos 2.x 的 gRPC 升级大幅提升了推送效率,但也对网络基础设施提出了更高要求。遇到。

奶爸的编程之路,也就一周冷个三天 365

WCF开发

无废话WCF入门教程一:https://www.cnblogs.com/iamlilinfeng/archive/2012/09/25/2700049.html WCF合并了Web服务、网络通讯,.net Remoting、消息队列和Enterprise Services的功能并集成在Visual Studio中。 特点:面向服务开发,支持分布式开发! 重要步骤: 创建WCF服务应用程序 ...

静以修身 551

RAGFlow 系列教程 第14课:GraphRAG -- 知识图谱增强检索

RAGFlow v0.25.0深度解读了GraphRAG技术,通过构建知识图谱解决传统RAG在多跳推理问题上的局限。系统支持General GraphRAG和Light GraphRAG两种实现,包含四阶段构建流程:实体关系抽取、实体消解、社区检测和图持久化。核心代码位于rag/graphrag目录,采用LLM驱动的抽取机制,结合编辑距离和LLM确认的实体消解策略,以及Leiden社区检测算法。KGSearch模块通过多信号融合检索(实体+关系+N-hop+社区)实现高效查询。该系统将非结构化文本转化为可推

weixin_43674738的博客 103

WCF分布式开发步步为赢(0):WCF学习经验分享,如何更好地学习WCF?

WCF分布式开发学习,应该从哪里开始?   学习WCF是不是就不需要学习Enterprise Sevices(COM+).Net Remoting、Web Service(ASMX)、WSE3.0和MSMQ消息队列?   WCF分布式开发学习,如何制定一个合理的计划,才能更好地学习WCF分布式应用开发。应该从哪里开始?   如何下载和安装WCF开发相关的组件。   有什么好的学习书籍、论坛?  

微软特邀讲师 老徐FrankXuLei 的专栏 2260

NLTK中WordNet与同义词处理

通过本教程,学习了如何使用NLTK中的WordNet进行自然语言处理任务。首先介绍了WordNet的基本概念及其在NLTK中的集成使用,接着讲解了如何查找同义词、反义词等词汇关系,并结合实际应用演示了语义相似性计算。这些技能在文本分析、情感分析、信息检索等场景中有广泛应用,可以帮助开发者构建更智能的自然语言处理系统。掌握这些基本操作后,可以进一步探索WordNet的其他高级功能,结合其他NLTK工具进行更复杂的语言分析。

Mr数据杨 481

Python库CloudScraper详细使用(绕过 Cloudflare 的反机器人页面的 Python 模块)

CloudScraper是一个专门用于绕过Cloudflare反机器人保护的Python库,它基于requests库构建,能够处理Cloudflare的5秒盾、WAF和人机验证等防护机制。

数据知道的博客 1万+

WCF

1、WCF定义: 1.1、是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分。由 .NET Framework 3.0 开始引入 1.2、WCF的最终目标是通过进程或不同的系统、通过本地网络或是通过Internet收发客户和服务之间的消息。 1.3、WCF合并了Web服务、.net Remoting、消息队列和Enterprise Ser...

weixin_45408840的博客 454

基于GPUMD的NEP机器学习势函数—二氧化硅融化

势函数作为分子动力学模拟中最终要的输入之一,其准确性很大程度上决定了模拟结果的可靠性,传统经验势无法很好地描述所有现象,而能进行准确预测的基于第一性原理计算的分子动力学计算量非常大,无法进行大体系长时间的计算。因此最近兴起的机器学习势函数正是解决这一问题的有效工具,它可以通过对第一性原理的计算结果进行学习,通过这个方法得到的势函数具有接近第一性原理的计算精度。这里介绍一种基于GPUMD的NEP机器学习方法。

Rockyoung 5326

wcf服务发布两个endpoint_「DDD」跟我一起学WCF(4)——第一个WCF程序

一、引言 前面几篇文章分享了.NET 平台下其他几种分布式技术,然而前面几种分布式技术专注于某一特定的领域,并且具有不同编程接口,这使得开发人员需要掌握多个API的使用。基于这样的原因,微软在.NET 3.0时实现了WCF。WCF是.NET平台下各种分布式技术的集成,它将前面介绍的几种分布式技术完全整合在一起,并提供了一套统一的编程接口(API)。对于,开发人员来来说只需要掌握WCF一套的API,...

weixin_39557402的博客 132

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

我的WCF之旅(1):创建一个简单的WCF程序

为了使读者对基于WCF的编程模型有一个直观的映像,我将带领读者一步一步地创建一个完整的WCF应用。本应用功能虽然简单,但它涵盖了一个完整WCF应用的基本结构。对那些对WCF不是很了解的读者来说,这个例子将带领你正式进入WCF的世界。在这个例子中,我们将实现一个简单的计算服务(CalculatorService),提供基本的加、减、乘、除的运算。和传统的分布式通信框架一样,WCF本质上提供一

Giraffe_zj的专栏 1435

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

WCF分布式开发常见错误解决(9):无终结点监听,There was no endpoint listening at

Posted on 2009-05-08 23:59 Frank Xu Lei 阅读(535) 评论(0)  编辑 收藏 网摘 所属分类: WCF分布式开发常见错误 <!--<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"xmlns:dc="http://purl.org/d

微软特邀讲师 老徐FrankXuLei 的专栏 7426

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

WCF教程二之WCF架构

WCF是一个分层次的架构,可以充分支持分布式程序的开发,在开发过程中WCF服务和应用程序之间的层次关系如下: 契约 WCF利用契约这个概念将服务和服务的操作定义为一个整体,以解释通过网络传输的数据,WCF主要区分数据契约,服务契约,消息契约以及Policy&Binding。Service contract - 服务契约 服务契约定义了服务向外界公开的功能,

hcshen的博客 713

WCF分布式开发常见错误(29):Unrecognized attribute 'targetFramework' (未识别的属性'targetFramework' )

Posted on 2010-03-22 21:30 Frank Xu Lei 阅读(16) 评论(0)  编辑 收藏 所属分类: WCF分布式开发常见错误 <!--<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"xmlns:dc="http://purl.org/dc/ele

微软特邀讲师 老徐FrankXuLei 的专栏 2542

WCF 分布式通信技术详解与实现方案

Windows Communication Foundation (WCF) 是微软推出的统一编程模型,用于构建分布式应用程序。它整合了早期的分布式通信技术(如.NET Remoting、Web Services 等),提供了跨平台、跨协议的通信能力。支持多种传输协议(HTTP、TCP、Named Pipes 等)提供多种消息编码格式(文本、二进制、MTOM)内置完善的安全机制(身份验证、授权、加密)支持多种服务托管方式(IIS、Windows 服务、控制台应用等)// 定义数据契约set。

品质生活,极致编程。 815

WCF(4)之第一个WCF程序

一、引言   前面几篇文章分享了.NET 平台下其他几种分布式技术,然而前面几种分布式技术专注于某一特定的领域,并且具有不同编程接口,这使得开发人员需要掌握多个API的使用。基于这样的原因,微软在.NET 3.0时实现了WCF。WCF是.NET平台下各种分布式技术的集成,它将前面介绍的几种分布式技术完全整合在一起,并提供了一套统一的编程接口(API)。对于,开发人员来来说只需要掌握WCF一套的A...

IT_0802的博客 453
上一篇: 解决RedHat安装时显卡选择错误无法进入XWindow的问题
下一篇: Host WCF Service in WAS
blacksource
博客等级 码龄21年 66粉丝 23原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值