1、先引用服务。
2、在生成的服务的Reference.cs里创建一个class,继承自 System.ServiceModel.Channels.MessageHeader
public class SessionIdHeader : System.ServiceModel.Channels.MessageHeader
{
public SessionIdHeader(string sessionId)
{
SesssionId = sessionId;
}
public string SesssionId { get; set; }
protected override void OnWriteStartHeader(System.Xml.XmlDictionaryWriter writer, System.ServiceModel.Channels.MessageVersion messageVersion)
{
writer.WriteStartElement("ns1", Name, Namespace);
writer.WriteXmlnsAttribute("ns1", Namespace);
}
protected override void OnWriteHeaderContents(System.Xml.XmlDictionaryWriter writer, System.ServiceModel.Channels.MessageVersion messageVersion)
{
writer.WriteValue(SesssionId);
}
public override string Name
{
get { return "SessionId"; }
}
public override string Namespace
{
get { return "http://login.webservice.bos.kingdee.com"; }
}
}
2、调用
//登录服务的调用
var client = new EASLoginService.EASLoginProxyClient(EASLoginService.EASLoginProxyClient.EndpointConfiguration.EASLogin);
var loginResult = await client.loginAsync(“user”, “user123”, “eas”, “xwf220318”, “12”, 2);
//其它服务调用,并将登录服务里的SessionId带过去。
var client2 = new WSFullOrgUnitFacadeService.WSFullOrgUnitFacadeSrvProxyClient(WSFullOrgUnitFacadeService.WSFullOrgUnitFacadeSrvProxyClient.EndpointConfiguration.WSFullOrgUnitFacade);
using (new OperationContextScope(client2.InnerChannel))
{
MessageHeaders messageHeadersElement = OperationContext.Current.OutgoingMessageHeaders;
messageHeadersElement.Add(new WSFullOrgUnitFacadeService.SessionIdHeader(loginResult.loginReturn.sessionId));
var result = await client2.queryOrgUnitAsync("2010-01-01");
}