C#调用java 编写的webservice时不会自动生成 soapheader 类接口的,需要改动Reference.cs。
在生成的代理类referende.cs中进行如下操作:在声明public new string Url{....}前声明public AuthenticationToken header { get; set; },然后在相应位置添加
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public class AuthenticationToken : System.Web.Services.Protocols.SoapHeader
{
/// <remarks/>
public string Username{ get; set; }
/// <remarks/>
public string Password { get; set; }
}
在要调用的接口的方法前添加
/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("header")]
页面上调用: GuestService gs = new GuestService();
AuthenticationToken t = new AuthenticationToken();
t.Username = "admin123";
t.Password = "admin123";
gs.header = t;
return gs;
也可以把该调用写进一个类里更方便。