企业需要对U9做一些客开的操作。U9客开有多种形式,其中OpenAPI,WebService的方案有实际项目运行中。有一种另类的客开方案,一直掌控不到位。做程序的总是想着有点标新立异的存在嘛。从没有放弃过,直到终于搞定!
客开方案是用友U9开发群里面的高手无私的开源。认为其思想更能匹配我的思维习惯,应用场景更灵活吧。不同客开方案结合起来使用,开发效率提升不小。
碰到过的坑记录一下。以免日后忘记又要不眠不休的煎熬。
1、web.config文件中要加入以下内容,再iisreset重启一下IIS。
文件的路径是,D:\yonyou\U9CE\Portal
<!--自定义代理路径-->
<add key="CustomProxyPath" value="CustomProxy" />
<!--自定义代理是否启用热加载-->
<add key="CustomProxyHotLoad" value="true" />
<!--自定义代理热加载触发时长(秒)-->
<add key="CustomProxyHotLoadTimeSeconds" value="5" />
踩坑最深的是此处,调试时不停提示找不到文件,原来是此处没有配置路径信息!-CustomProxy是自定义,用来存放接口文件的目录。
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin;_app_bin;UBFLib;ApplicationLib;CustomProxy" />
</assemblyBinding>
2、Apifox调试时,注意JSON的格式。如下。从这里可以看到,另类的客开思维是纯正的反射应用。利用的是U9原生态的dll库。格式也是标准固定化的,符合用户习惯,变化大的话,理解上也是困难。
{
"context": {
"enterpriseID": "100",
"orgCode": "100",
"userCode": "admin",
"password": ""
},
"proxy": "UFIDA.U9.NPMFG.CustomProxy.SubmitPO,UFIDA.U9.NPMFG.CustomProxy",
"data": {
"pODocNo": "DPO0225080260"
}
}
3、这套客开方案起源时间较久,技术概念上有了差异。似乎高手们也很少使用它的。碰到的坑时,JSON格式处理上的差异造成的。
<!--通用代理服务-->
<service name="UFIDA.U9.WSS.ProxyService.Services.ProxyService">
<endpoint address="" behaviorConfiguration="ProxyServiceEndPointBehavior"
binding="webHttpBinding"
bindingConfiguration="restWebHttpBinding"
contract="UFIDA.U9.WSS.ProxyService.Interfaces.IProxyService" />
</service>
实际上是请求格式标准, / Content-Type / WrappedRequest 与 BodyStyle = WebMessageBodyStyle.Bare 的差异导致了调试时,总是报415错误。其中,
如果不想包一层
request,可以把接口改成:WebInvoke( Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)
对应的JSON格式是,
{
"context": {
"enterpriseID": "100",
"orgCode": "100",
"userCode": "admin",
"password": ""
},
"queryCond": {
"entityFullName": "UFIDA.U9.MO.MO.MO",
"selectClause": "ID,ProductQty",
"whereClause": "Org=#Context.OrgID# and ProductQty>1000000",
"orderByClause": "CreatedOn desc"
},
"pageParamter": {
"pageIndex": 1,
"pageSize": 10
}
}
没有 "request": { } 包起来。
WebInvoke( Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)
对应的JSON格式如下,
{
"request": {"queryCond": {
"entityFullName": "UFIDA.U9.MO.MO.MO",
"selectClause": "ID,ProductQty",
"whereClause": "Org=#Context.OrgID# and ProductQty>1000000",
"orderByClause": "CreatedOn desc"
},
"pageParamter": {
"pageIndex": 1,
"pageSize": 10
}
}
}