2010-01-06 86 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); 
      } 
     } 
    } 
}`