asp.net web服务soap标头在客户端服务调用中显示为参数

asp.net web服务soap标头在客户端服务调用中显示为参数,asp.net,web-services,Asp.net,Web Services,我只是尝试使用soap头进行身份验证 向客户端控制台应用程序添加服务引用后,标头将显示为列表中的第一个参数,而不是客户端对象上的成员 有人知道我做错了什么吗 网络服务: public class Service1 : System.Web.Services.WebService { public CustomSoapHeader MyHeader; [WebMethod] [SoapHeader("MyHeader")] public string HelloW

我只是尝试使用soap头进行身份验证

向客户端控制台应用程序添加服务引用后,标头将显示为列表中的第一个参数,而不是客户端对象上的成员

有人知道我做错了什么吗

网络服务:

public class Service1 : System.Web.Services.WebService
{
    public CustomSoapHeader MyHeader;

    [WebMethod]
    [SoapHeader("MyHeader")]
    public string HelloWorld()
    {
        return "Hello World";
    }

    public class CustomSoapHeader : SoapHeader
    {
        public string SomeProperty { get; set; }
    }
}
客户:

class Program
{
    static void Main(string[] args)
    {
        Service1SoapClient client = new Service1SoapClient();
        client.HelloWorld(new CustomSoapHeader());
    }
}
如果“服务引用”指的是WCF客户端,那么问题在于服务器不是WCF服务器。如果将引用添加为“Web引用”,则标头应显示为客户端代理类的成员

using System;
using System.Windows.Forms;

namespace WebClient
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            // For Web Reference:
            //ServiceReference1.HelloWorldRequest = new WebClient.ServiceReference1.HelloWorldRequest();
            //label1.Text = webService.GetClientTime(5).ToString(); 

            string baseURL = "http://localhost:11674/Service1.asmx";

            // Create the SystemService Client
            // Looking to the ap.config for "Service1Soap" binding string.
            ServiceReference1.Service1SoapClient systemService
                = new ServiceReference1.Service1SoapClient("Service1Soap", baseURL);

            label1.Text = systemService.HelloWorld();

            WebClient.ServiceReference1.Auth myAuf = new WebClient.ServiceReference1.Auth();

            myAuf.password = "test";
            myAuf.user = "test";

            try
            {
                label2.Text = systemService.GetClientTime(myAuf, 0).ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            } 
        }
    }
}`