2010-01-06 98 views
2

我只是试图使用肥皂头进行身份验证的目的。asp.net Web服务肥皂标题出现在客户服务调用

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

任何人有任何想法我做错了什么?

的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()); 
    } 
} 

回答

1

如果 “服务引用” 你的意思是WCF客户端,那么问题是,服务器并不是一个WCF服务器。如果您将引用添加为“Web引用”,则标题应该显示为客户端代理类的成员。

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); 
      } 
     } 
    } 
}`