Web Service 不引用SDK方式 新增【用户】 【分享】
金蝶云社区-云社区用户4u731234
云社区用户4u731234
0人赞赏了该文章 4,515次浏览 未经作者许可,禁止转载编辑于2014年11月20日 14:54:45

//Web Service不引用SDK方式 新增【用户】 (Cloud5.0)
//新建立.net 控制台应用程序Copy代码按如下设置可直接运行
//引用发布的SI站点Web Service。引用地址: http://localhost:8089/K3CloudServiceInterface/soap12?includAllTypes=1

//通过如下代码,可新增用户名 WebServiceDemo的登陆用户,并且绑定组织编码100及角色编码BOS01_SYS

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;

using ConsoleApplication.WebService.ServiceReference1;

namespace ConsoleApplication.WebService
{
class Program
{
static void Main(string[] args)
{
string EndpointUri = "http://localhost/K3CloudServiceInterface/soap12";

var binding = new System.ServiceModel.WSHttpBinding
{
MaxReceivedMessageSize = int.MaxValue,
HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
MaxBufferPoolSize = 524288,
};
binding.Security.Mode = SecurityMode.None;
binding.AllowCookies = true;

using (var client = new SyncReplyClient(
binding,
new EndpointAddress(EndpointUri)))
{
//登录
var result = client.Auth("credentials", "Administrator", "888888", false, true);
Console.WriteLine("Auth");
if (result.ResponseStatus.IsSuccess)
{
Console.WriteLine("Auth: succeeded");

SEC_User model = CreateModel();

Console.WriteLine("SEC_User_Save");
//新增用户
var resultSave = client.SEC_User_Save("WebServiceDemo", model , new string[] { });

string sInfo = string.Concat("SEC_User_Save: ", resultSave.ResponseStatus == null ? "succeeded" : "failed");
Console.WriteLine(sInfo);

if (resultSave.ResponseStatus != null)
{
StringBuilder sb = new StringBuilder();
foreach (var item in resultSave.ResponseStatus.Errors)
{
sb.AppendLine(item.Message);
}

Console.WriteLine(sb.ToString());
}
Console.ReadKey();
}
}
}

private static SEC_User CreateModel()
{
//构造数据 SEC_User 【用户】
SEC_User user = new SEC_User();
user.FUserAccount = "WebServiceDemo";
user.FName = "WebServiceDemo";

user.SEC_User__FOrgInfo = new SEC_User__FOrgInfo[]
{
new SEC_User__FOrgInfo()
{
FOrgOrgId = new SEC_User_ORG_OrganizationsForSelect()
{
FNumber = "100"
},
SEC_User__FRoleInfo = new SEC_User__FRoleInfo[]
{
new SEC_User__FRoleInfo()
{
FRoleId = new SEC_User_SEC_KDRoles()
{
FNumber="BOS01_SYS"
}
}
}
}
};
return user;
}

}
}