PowerShell的Salesforce的SOAP API SessionHeader类型Converion问题 [英] Powershell Salesforce SOAP API SessionHeader Type Converion Issue

查看:191
本文介绍了PowerShell的Salesforce的SOAP API SessionHeader类型Converion问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我有麻烦设置SessionHeaderValue。我立足于C#.NET我的code。登录作品和我收到在登录结果的serviceUrl和的sessionId,但我不能得到会话ID在会话头设置

Hi I am having trouble setting the SessionHeaderValue. I am basing my code on c#.Net. The login works and I receive the serviceUrl and sessionId in the login result but I can't get the session Id set in the session header

下面是code

$uri = "c:\installs\sforce.wsdl"
$username = "username"
$password = "password"
# Proxy
$service = New-WebServiceProxy -Uri $uri -Namespace sforce -UseDefaultCredential
# Login
$loginResult = $service.login($username, $password)
$service.Url = $loginResult.serverUrl
$service.SessionHeaderValue = New-Object sforce.SessionHeader

这是我得到的是一个有点古怪的错误。

This is the error I get which is a bit odd.

例外设置SessionHeaderValue:,不能转换sforce.SessionHeader sforce.SessionHeader的类型值,输入sforce.SessionHeader

Exception setting "SessionHeaderValue": "Cannot convert the "sforce.SessionHeader" value of type "sforce.SessionHeader" to type "sforce.SessionHeader"."

我一直在现在玩这个了几个小时,并已江郎才尽。

I have been playing with this for a few hours now and have run out of ideas.

任何帮助是AP preciated。

Any help is appreciated.

安东尼

推荐答案

真正的问题是,你不能重复使用 $服务。你的 $服务的实例只用于登录好,仅此而已。我认为这是由于新的方式 - WebServiceProxy工作。检查这个脚本了:

The real problem is that you can't reuse $service. Your instance of $service is only good for the login, and that's it. I think it's due to the way New-WebServiceProxy works. Check this little script out:

$uri = 'file://C:\projects\CRM\SalesForce\Integration\enterprise.xml'
$api = new-webserviceproxy -uri $uri -NameSpace SalesForce

$api.GetType().Module.Assembly.ManifestModule.ScopeName

$api = new-object SalesForce.SforceService.ScopeName
$api.GetType().Module.Assembly.ManifestModule

如果您要运行此脚本,(当然你需要替换自己的WSDL),你会看到这样的事情(这些DLL是动态的,所以名称会有所不同):

If you were to run this script, (of course you'd need to substitute your own WSDL), you'd see something like this (the DLLs are dynamic, so the names will be different):

mhgl0l5w.dll 
vzecopaq.dll

注意,不仅是为$ API不同,但新WebServiceProxy创建动态装配的对象引用是为每一个不同的,这是不是你所期望的。这就是为什么你投的原因是没有;因为他们来自不同的动态组件具有相同名称的对象是不同的。我不知道为什么的行为是这样 - 如果它在Salesforce的WSDL的新WebServiceProxy的特点,或以某种方式

Notice that not only are the object references for $api different, but the dynamic assembly that New-WebServiceProxy creates is different for each one, which isn't what you might expect. That's why your cast is failing; your objects with the same name are different because they come from different dynamic assemblies. I'm not sure why the behavior is this way - if it's a peculiarity of New-WebServiceProxy, or somehow in SalesForce's WSDL.

该解决方案实际上是pretty简单。重新创建服务对象关闭的新WebServiceProxy像这样产生的命名空间:

The solution is actually pretty simple. Recreate your service object off the namespace generated by New-WebServiceProxy like so:

$uri = "c:\installs\sforce.wsdl"
$username = "username"
$password = "password"
# Proxy
$service = New-WebServiceProxy -Uri $uri -Namespace sforce -UseDefaultCredential

# Login
$loginResult = $service.login($username, $password)

$service = New-Object sforce.SforceService
$service.Url = $loginResult.serverUrl
$service.SessionHeaderValue = New-Object sforce.SessionHeader

这篇关于PowerShell的Salesforce的SOAP API SessionHeader类型Converion问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆