调用 crm4 web 服务时出现错误 401
我的这段代码可以在单元测试中工作,但在插件上下文中执行时不起作用。 该代码的作用是尝试通过调用 crm4 Web 服务来创建潜在客户。
当插件执行时,我收到以下异常:“HTTP 状态 401:未经授权”
这是初始化 Web 服务实例的代码
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = GetConfig("crm.organisation_name");
_crmService = new CrmService(GetConfig("webservice.crm"));
_crmService.CrmAuthenticationTokenValue = token;
_crmService.UseDefaultCredentials = false;
_crmService.PreAuthenticate = false;
_crmService.Credentials = new NetworkCredential(GetConfig("crm.user_username"),
GetConfig("crm.user_password"),
GetConfig("crm.user_domain"));
有人对我下一步可以尝试什么有建议吗? 测试运行时会创建线索,单元测试中的配置信息与应用程序执行插件时的配置信息相同。
I have this code that works in a unit test but doesn't work when executed in the context of a plugin. What the code does is try to create a lead by calling the crm4 webservice.
When the plugin executes I get the following exception: "HTTP status 401: Unauthorized"
This is the code that initialises an instance of the webservice
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = GetConfig("crm.organisation_name");
_crmService = new CrmService(GetConfig("webservice.crm"));
_crmService.CrmAuthenticationTokenValue = token;
_crmService.UseDefaultCredentials = false;
_crmService.PreAuthenticate = false;
_crmService.Credentials = new NetworkCredential(GetConfig("crm.user_username"),
GetConfig("crm.user_password"),
GetConfig("crm.user_domain"));
Anyone have advice on what I can try next? The lead is created when the test runs, and the configuration information is the same in the unit test as it is when the app is executing the plugin.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不必自己实例化 CrmService,也可以通过获取 IPluginExecutionContext 的引用并调用 CreateCrmService 方法来获取 CrmService。
请参阅此 关于从 IPluginExecutionContext 创建 CrmService 的链接
问候,
hadi
Rather than instantiating the CrmService by yourself, alternatively you can obtain the CrmService by obtaining the reference of the IPluginExecutionContext and invoke the CreateCrmService method
Please refer to this link regarding creating the CrmService from IPluginExecutionContext
Regards,
hadi