一、在portal/services目录下找到新增杂收的服务名,在浏览器里输入地址,看能不能调通:http://localhost/Portal/services/UFIDA.U9.ISV.MiscRcvISV.ICommonCreateMiscRcv.svc
二、生成桩代码:批处里改为
NetCFSvcUtil.exe /namespace:*,ICommonCreateMiscRcv http://localhost/portal/services/UFIDA.U9.ISV.MiscRcvISV.ICommonCreateMiscRcv.svc?wsdl
pause
其中ICommonCreateMiscRcv为命名空间。
三、新建一个Winform项目,把生成的桩代码拷贝到项目里,查找threadcontext,把找到的两个类注释,再按一次回车,把threadcontext解析。项目添加System.servicemodel引用,引用路径为:C:/Program Files/Reference Assemblies/Microsoft/Framework/v3.0/System.ServiceModel.dll。从其他项目拷贝文件ThreadContext.cs、CFClientBase.cs、CallSV.cs。其中需要修改CallSV.cs代码如下:
//第一个类型为返回值类型,第二个参数为传入参数类型,第三个从桩代码里查找client得到。
public static ICommonCreateMiscRcv119.UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] GenernateMiscRcv(ICommonCreateMiscRcv119.UFIDAU9ISVMiscRcvISVIC_MiscRcvDTOData[] BLISVcreatemiscrcv)
{
System.ServiceModel.Channels.Binding binding = ICommonCreateMiscRcv119.UFIDAU9ISVMiscRcvISVICommonCreateMiscRcvClient.CreateDefaultBinding();
binding.SendTimeout = new TimeSpan(0, min, 0);
string remoteAddress = ICommonCreateMiscRcv119.UFIDAU9ISVMiscRcvISVICommonCreateMiscRcvClient.EndpointAddress.Uri.ToString();
remoteAddress = remoteAddress.Replace("u9sys", "192.168.0.119");
EndpointAddress endpoint = new EndpointAddress(remoteAddress);
ICommonCreateMiscRcv119.UFIDAU9ISVMiscRcvISVICommonCreateMiscRcvClient client = new ICommonCreateMiscRcv119.UFIDAU9ISVMiscRcvISVICommonCreateMiscRcvClient(binding, endpoint);
ThreadContext context = CallSV.CreateContextObj();
ICommonCreateMiscRcv119.MessageBase[] msg = null;
return client.Do(context, BLISVcreatemiscrcv, out msg);
#region 给上下文赋值 119 服务器 shankx 数据库
private static ThreadContext CreateContextObj()
{
// 实例化应用上下文对象
ThreadContext thContext = new ThreadContext();
ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType[] namevalues = new ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType[5];
namevalues[0] = new ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType();
namevalues[1] = new ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType();
namevalues[2] = new ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType();
namevalues[3] = new ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType();
namevalues[4] = new ArrayOfKeyValueOfanyTypeanyTypeKeyValueOfanyTypeanyType();
namevalues[0].Key = "OrgID";
namevalues[0].Value = "1001010200000025"; //1001010200000025 001 广州百利
namevalues[1].Key = "UserID";
namevalues[1].Value = "1001010200000191"; //1001010200000191 admin 系统管理员
namevalues[2].Key = "CultureName";
namevalues[2].Value = "zh-CN";
namevalues[3].Key = "EnterpriseID"; //0004 测试张套
namevalues[3].Value = "0004";
namevalues[4].Key = "EnterpriseName";
namevalues[4].Value = "192.168.0.119";
thContext.nameValueHas = namevalues;
return thContext;
}
#endregion
四,建一个Winform窗体,用来测试调用程序,窗体里只需要一个按钮,触发callSV里的调用服务的事件。
Winform.cs里的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ICommonCreateMiscRcv119;
using BLTest;
namespace BaiLiTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//数据是服务器里的
List<ICommonCreateMiscRcv119.UFIDAU9ISVMiscRcvISVIC_MiscRcvDTOData> headlist = new List<ICommonCreateMiscRcv119.UFIDAU9ISVMiscRcvISVIC_MiscRcvDTOData>();
ICommonCreateMiscRcv119.UFIDAU9ISVMiscRcvISVIC_MiscRcvDTOData head = new ICommonCreateMiscRcv119.UFIDAU9ISVMiscRcvISVIC_MiscRcvDTOData();
//单据类型 1001010210110817 MiscRcv001 库存杂收[默认]
UFIDAU9CBOPubControllerCommonArchiveDataDTOData doctype = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
doctype.m_iD = 1001010210110817;
doctype.m_iDSpecified = true;
doctype.m_code = "MiscRcv001";
head.m_miscRcvDocType = doctype;
List<UFIDAU9ISVMiscRcvISVIC_MiscRcvTransLsDTOData> lines = new List<UFIDAU9ISVMiscRcvISVIC_MiscRcvTransLsDTOData>();
UFIDAU9ISVMiscRcvISVIC_MiscRcvTransLsDTOData line = new UFIDAU9ISVMiscRcvISVIC_MiscRcvTransLsDTOData();
//料号 1001010296900136 301003-000002 VMD-TC02-00茶水柜顶板
UFIDAU9CBOSCMItemItemInfoData iteminfo = new UFIDAU9CBOSCMItemItemInfoData();
iteminfo.ItemID = 1001010296900136;
iteminfo.ItemIDSpecified = true;
iteminfo.m_itemCode = "301003-000002";
//iteminfo.m_itemName = "玛斯文件柜顶板V 01A";
line.m_itemInfo = iteminfo;
line.m_storeUOMQty = 5;//库存数量
line.m_storeUOMQtySpecified = true; //若为 false,则storeUOMQty 可有可无
line.m_costPrice = 123; //单价
line.m_costPriceSpecified = true;
line.m_costUOMQty = 5;//成本数量
line.m_costUOMQtySpecified = true;
UFIDAU9CBOPubControllerCommonArchiveDataDTOData wh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
//1001010296900518 WE003 玻璃/大理石仓
wh.m_iD = 1001010296900518;
wh.m_iDSpecified = true;
wh.m_code = "WE003";
wh.m_name = "玻璃/大理石仓";
line.m_wh = wh;
lines.Add(line);
//m_miscRcvTransLs杂收单行,单行是单头里的一个集合字段,属于单头,是一个列表
head.m_miscRcvTransLs = lines.ToArray();// new ICommonCreateMiscRcv.UFIDAU9ISVMiscRcvISVIC_MiscRcvTransLsDTOData[] { line };
headlist.Add(head);
try
{
ICommonCreateMiscRcv119.UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] docList = CallSV.GenernateMiscRcv(headlist.ToArray());
this.textBox1.Text = "调用成功:";
for (int i = 0; i < docList.Length; i++)
{
this.textBox1.Text += docList[i].m_code;
}
}
catch (System.Exception ex)
{
this.textBox1.Text = ex.StackTrace;
}
}
}
}
在Form1.cs里,使用代码绑定这些字段,把参数传完整,看是否能生成一张杂收单。就好像是在Portal里,用鼠标手动选择数据或输入数据的结果一样。
注意事项,具体要传什么字段,哪些是必传字段,可以登陆portal里,手动生成一张单,需要什么选项就传哪些字段。
字段是什么类型,是否集合等问题,可以从数据字典里查找。
每个字段要传什么值,必须从数据库里找到再赋,一般只需要code 或ID。
//数据字典结合Portal,看有哪些参数集
//参数传正确,完整了,就能生成一张杂收单
//name是存在CBO_Wh_trl表里,后加_trl,id,code存在CBO_Wh里
callSV里的替换地址,"laiwei-292cb496",本机的就是本机的,服务器的不一样(http://u9sys),要从桩代码里查找出到底是哪个地址
做服务的头与行是DTOData类型,常发生DTOData无法隐式转换为DTO类型。做杂收服务时,不要引用UFIDA.U9.ISV.MiscRcvISV.dll引用。否则会发生很多错误。
}