c# - soapheader认证

标签 c# web-services authentication soap

我无法让我的客户重新调整 Visual Studio 添加到代理类的 AuthHeaderValue 我看过很多例子,但找不到任何关于如何解决这个问题的方法。

SOAP 类

     public class AuthHeader : SoapHeader
     {
        public string Username;
        public string Password;

     }

网络服务

     public class Service1 : System.Web.Services.WebService
     {
        public AuthHeader Authentication; ** where does visual studio append value to proxy 

    [SoapHeader("Authentication", Required = true)]
    [WebMethod]
    public string security()
    {
        if (Authentication.Username == "test" &&
            Authentication.Password == "test")
        {
            return "authenticated";
        }
        else
        {
            return "get lost";
        }            
    }

客户

   static void Main(string[] args)
    {
        ServiceReference1.AuthHeader auth = new ServiceReference1.AuthHeader();
        auth.Username = "test";
        auth.Password = "test";

        ServiceReference1.Service1SoapClient ser = new ServiceReference1.Service1SoapClient();
        ser.AuthHeaderValue = auth;  ** does not reconise authheadervalue
        String message = ser.security();
        Console.WriteLine(message);

    }

最佳答案

您必须将身份验证参数值作为 header 的 TRUE 传递。 查看完整解决方案 here

关于c# - soapheader认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12158545/

相关文章:

c# - 自动生成的实体类中缺少导航属性

c# - 如何创建可以迭代的类集合?

java - Java 中的 RESTful Web 服务 - 400 错误请求 - 方法调用错误?

python - 如何在同一个应用程序中拥有两个登录/身份验证策略?

node.js - 使用 Passport.js 部分保护 API 端点

c# - 如何判断 ListView 正在显示哪些项目?

C# 在 Windows 中重新排列多显示位置

java - string.format 在 http post 请求和响应中抛出异常

wcf - 从 WCF 服务返回多个值的最佳方式是什么

java - 使用 Spring Boot Rest api 的 mysql 身份验证问题