我只是尝试使用soap标头进行身份验证。
将服务引用添加到客户端控制台应用程序后,标题显示为列表中的第一个参数,而不是客户端对象上的成员。
任何人都知道我做错了什么?
WebService的:
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());
}
}
答案 0 :(得分:1)
如果“服务引用”是指WCF客户端,则问题是服务器不是WCF服务器。如果将引用添加为“Web引用”,则标题应显示为客户端代理类的成员。
答案 1 :(得分:0)
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);
}
}
}
}`