惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
B
Blog RSS Feed
Y
Y Combinator Blog
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
aimingoo的专栏
aimingoo的专栏
Jina AI
Jina AI
The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Check Point Blog
M
MIT News - Artificial intelligence
Last Week in AI
Last Week in AI
V
V2EX
腾讯CDC
F
Fortinet All Blogs
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss

博客园 - 生命体验之kevin-Y

windbg内存占用分析常用命令 如何让Trae IDE调用windbg来分析dump文件 Avalonia.Controls.DataGrid自动合并列 asp.net core如何实现Controller热更新 windbg无法分析dotnetframework3.5的dmp asp.net core通过配置决定AddSingleton的实现类 vscode指定python文件的执行程序 golang离线开发-windows-vscode go语言学习 - caddy配置的一些发现 go语言学习 - caddy添加nacos-gateway 学习jsp-使用IDEA2024社区版 ravendb源代码学习一:服务启动 修整程序集需要 .NET Core 3.0 或更高版本。 打开电脑后一直弹出“交互式检测服务”窗口 Idea2024-java-Maven开发配置 C#获取事件绑定的方法 java.util.zip.DataFormatException: incorrect header check “System.Net.Http.HttpContent”不包含“ReadAsAsync”的定义 C#入门:如何合理制定方法参数-下 C#入门:如何合理制定方法参数-上 拷贝对象的开源工具类-FastMapper-TinyMapper-Mapster
Build Secure Web Services With SOAP Headers and Extensions
生命体验之kevin-Y · 2023-12-19 · via 博客园 - 生命体验之kevin-Y

原文如下:

https://www.developer.com/microsoft/dotnet/build-secure-web-services-with-soap-headers-and-extensions/

文章详细说了SOAPHeader使用的两种方式。我认为文中进行的验证都几乎就是明文传送的。加上一个body签名我认为是必要的。

string sign = HttpContext.Current.Request.Headers["sign"];

文章的内容,再加上上面这一句,我就能改造了。

摘录我最想要的Extensions部分。

<%@ WebService Language="C#" Class="QuoteService" %>

using System;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService (
    Name="Quote Service",
    Description="Provides instant stock quotes to registered users"
)]
public class QuoteService
{
    public AuthHeader Credentials;

    [AuthExtension]
    [SoapHeader ("Credentials", Required=true)]
    [WebMethod (Description="Returns the current stock price")]
    public decimal GetQuote (string symbol)
    {
        if (symbol.ToLower () == "msft")
            return 55.0m;
        else if (symbol.ToLower () == "intc")
            return 32.0m;
        else
            throw new SoapException ("Unrecognized symbol",
                SoapException.ClientFaultCode);
    }
}

public class AuthHeader : SoapHeader
{
    public string UserName;
    public string Password;
}

[AttributeUsage (AttributeTargets.Method)]
public class AuthExtensionAttribute : SoapExtensionAttribute
{
    int _priority = 1;

    public override int Priority
    {
        get { return _priority; }
        set { _priority = value; }
    }

    public override Type ExtensionType
    {
        get { return typeof (AuthExtension); }
    }
}

public class AuthExtension : SoapExtension
{
    public override void ProcessMessage (SoapMessage message)
    {
        if (message.Stage == SoapMessageStage.AfterDeserialize) {
            //Check for an AuthHeader containing valid
            //credentials
            foreach (SoapHeader header in message.Headers) {
                if (header is AuthHeader) {
                    AuthHeader credentials = (AuthHeader) header;
                    if (credentials.UserName.ToLower () ==
                        "jeff" &&
                        credentials.Password.ToLower () ==
                        "imbatman")
                        return; // Allow call to execute
                    break;
                }
            }

            // Fail the call if we get to here. Either the header
            // isn't there or it contains invalid credentials.
            throw new SoapException ("Unauthorized",
                SoapException.ClientFaultCode);
        }
    }

    public override Object GetInitializer (Type type)
    {
        return GetType ();
    }

    public override Object GetInitializer (LogicalMethodInfo info,
        SoapExtensionAttribute attribute)
    {
        return null;
    }

    public override void Initialize (Object initializer)
    {
    }
}