public static CookieContainer c = new CookieContainer();//定义Cookie容器
/// <summary>
/// 金蝶登录接口
/// </summary>
/// <returns></returns>
private WSContext JinDieLogin()
{
System.Net.ServicePointManager.Expect100Continue = false;
EASLoginProxyService service = new EASLoginProxyService();//登录服务
service.CookieContainer = c;//使用同一个Cookie容器
WSContext ctx = service.login(jinDieConfigInfo.userName, jinDieConfigInfo.password, jinDieConfigInfo.slnName, jinDieConfigInfo.dcName, jinDieConfigInfo.language, jinDieConfigInfo.dbType);//登录参数,根据自己实际填写
return ctx;
}
/// <summary>
/// 开票申请单
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Data"></param>
/// <returns></returns>
public JinDieEASResponse Invoicing<T>(T Data)
{
var context = JinDieLogin();//调用登录接口
WSOkWebServiceFacadeSrvProxyService _jindieService = new WSOkWebServiceFacadeSrvProxyService();//业务服务
_jindieService.CookieContainer = c;//使用同一个Cookie容器
_jindieService.SessionId = new KDSessionId() { SessionId = context.sessionId };
var resultData = _jindieService.invoicing(SurroundData(Data));//收款单接口
return Serializer.Deserialize<JinDieEASResponse>(resultData);
}
“登录服务”与“业务服务”使用就完成了,但是实际使用会发现 _jindieService.SessionId 会点不出来。
这是因为需要我们手动添加,我们修改一下引入的webservice
在引入webservice 业务服务类中,添加红框的内容
public class KDSessionId : SoapHeader
{
public string SessionId;//变量名与接口定义同名
}
public KDSessionId SessionId;