首页产品库评测行情新闻|手机数码笔记本台式机DIY硬件数字家庭数码相机办公外设|软件下载游戏开发|社区

更多

数码相机
MP4
LCD
机箱
音箱

软件资讯设计 工具 系统 开发 安全 办公 陶吧 IT教育 Vista频道 | 下载中心酷我音乐盒 腾讯QQ
天极网 > 开发频道>化零为整WCF(5)-宿主Hosting

化零为整WCF(5)-宿主Hosting

2008-05-25 07:00作者:webabcd出处:天极网责任编辑:nancy

  3、客户端

  Hello.aspx

 


<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Hello.aspx.cs"
    Inherits="Hosting_Hello" Title="宿主Hosting(服务宿主在WindowsService)" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div>
        <ul>
            <li style="color: Red;">本例为宿主在WindowsService的示例</li>
            <li>宿主在IIS请参见本解决方案的ServiceHost项目</li>
            <li>宿主在应用程序请参见本解决方案的ServiceHost2项目</li>
            <li>应用程序自宿主就是把本解决方案的ServiceLib项目和ServiceHost2项目结合在一起</li>
            <li>宿主在Windows Activation Services(WAS),因为我没有环境,就先不写示例了</li>
        </ul>
    </div>
    <asp:TextBox ID="txtName" runat="server" Text="webabcd" />
    &nbsp;
    <asp:Button ID="btnSayHello" runat="server" Text="Hello" OnClick="btnSayHello_Click" />
</asp:Content>
  

   


Hello.aspx.cs
  using System;
  using System.Collections;
  using System.Configuration;
  using System.Data;
  using System.Linq;
  using System.Web;
  using System.Web.Security;
  using System.Web.UI;
  using System.Web.UI.HtmlControls;
  using System.Web.UI.WebControls;
  using System.Web.UI.WebControls.WebParts;
  using System.Xml.Linq;
  
  public partial class Hosting_Hello : System.Web.UI.Page
  {
   protected void Page_Load(object sender, EventArgs e)
   {
  
   }
  
   protected void btnSayHello_Click(object sender, EventArgs e)
   {
   var proxy = new HostingByWindowsService.HelloClient();
  
   Page.ClientScript.RegisterStartupScript(
   this.GetType(),
   "js",
   string.Format("alert('{0}')", proxy.SayHello(txtName.Text)),
   true);
  
   proxy.Close();
   }
  }
  

  Web.config

  


<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <client>
      <!--address - 服务地址-->
      <!--binding - 通信方式-->
      <!--contract - 服务契约-->
      <endpoint address="http://localhost:11233/ServiceHostByWindowsService/" binding="wsHttpBinding" contract="Sample.IHello" />
    </client>
  </system.serviceModel>
</configuration>

  运行结果:

  启动"WCF.ServiceHostByWindowsService"服务,单击"Hello"按钮后弹出提示框,显示"Hello: webabcd"

原文链接:http://www.cnblogs.com/webabcd/archive/2008/04/07/1139938.html

关注此文的读者还看过:

返回开发频道首页

共3页。 上一页123

软件频道最新更新

热点推荐

IT嘉年华

编辑推荐

软件下载

热门
推荐

网友关注

软件
资料
游戏

装机推荐

文章排行

本周
本月
最新更新
天极服务|关于我们|About us|网站律师|RSS订阅|友情合作|加入我们|天极动态|网站地图|意见反馈|MSN/QQ上看天极
Copyright (C) 1999-2012 Yesky.com, All Rights Reserved 版权所有 天极网络