zoukankan      html  css  js  c++  java
  • WebService 身份验证01_SoapHeader及 iis windows 集成身份验证

    1 SoapHeader 验证

    服务端:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    
    namespace WebApplication2
    {
        /// <summary>
        /// WebService2 的摘要说明
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 
        // [System.Web.Script.Services.ScriptService]
        public class WebService2 : System.Web.Services.WebService
        {
    
            public UserValidationSoapHeader UserValidation;
    
            [WebMethod]
            [SoapHeader("UserValidation")]
            public string HelloWorld()
            {
                return $"userName:{UserValidation.UserName}passwd:{UserValidation.Passward}";
            }
        }
    
    
        public class UserValidationSoapHeader : SoapHeader
        {
            public UserValidationSoapHeader()
            {
    
            }
            public string UserName { get; set; }
            public string Passward { get; set; }
    
        }
    
    } 

    服务端配置文件开启远程访问:

     

      <!--本地 要在web.config下的 <system.web>下添加(开启远程访问。。)-->
    <webServices>
             <protocols>
                <add name="HttpSoap"/>
                <add name="HttpPost"/>
                <add name="HttpGet"/>
                <add name="Documentation"/>
             </protocols>
    </webServices>  

    客户端:

      static void Main(string[] args)
            {
    
                WebService.WebService2 service2 = new  WebService.WebService2();
                service2.UserValidationSoapHeaderValue = new WebService.UserValidationSoapHeader() { UserName = "hnzheng", Passward = "123" };
                service2.UserValidationSoapHeaderValue.Actor = "http://www.baidu.com";
                service2.HelloWorld();
                Console.ReadLine();
            }
    

      

    2  集成身份验证

    2、客户端引用代码

    localhost.WebService service = new localhost.WebService();
    service.Credentials = new NetworkCredential("xxx","123"); //xxx是用户名,123是密码
    string result = service.HelloWorld("测试");

  • 相关阅读:
    【逆序对】N*M Puzzle / Simple Puzzle
    【逆序对】Ultra
    bzoj 1814 Fornula 1
    hdu 1693 插头dp入门
    bzoj 2154
    没有上司的舞会
    【HNOI】合唱队
    luogu 自适应Simpson2
    luogu 自适应Simpson1
    【bzoj 1502】月下柠檬树
  • 原文地址:https://www.cnblogs.com/hnzheng/p/12728994.html
Copyright © 2011-2022 走看看