龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > asp.net编程 >

ASP.NET调用WebService安全认证基于SoapHeader实现(2)

时间:2009-12-21 11:47来源:未知 作者:admin 点击:
分享到:
3.客户端调用,分别使用不设置SoapHeader与设置SoapHeader。 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace App { class Program { static v

3.客户端调用,分别使用不设置SoapHeader与设置SoapHeader。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App
{
    class Program
    {
        static void Main(string[] args)
        {

            localhost.WebService service = new localhost.WebService();

            //没有设置SoapHeader的服务调用
              Console.WriteLine("没有设置SoapHeader:" + service.HelloWord());
            Console.WriteLine();

            //将用户名与密码存入SoapHeader;
            localhost.MySoapHeader header = new localhost.MySoapHeader();
            header.UserName = "houlei";
            header.PassWord = "houlei";
            service.MySoapHeaderValue = header;

            //设置SoapHeader的服务调用
              Console.WriteLine("设置SoapHeader:" + service.HelloWord());
            Console.Read();
        }
    }
}
4.运行应用程序,查看运行结果。

image

再看一下直接通过浏览器的调用结果。

image


精彩图集

赞助商链接