powershell - 使用 PowerShell 查询 CRM 2011 SOAP 端点

标签 powershell dynamics-crm-2011 dynamics-crm

我正在尝试通过 PowerShell 和 SOAP 查询 CRM 2011。以下 PowerShell 脚本应返回联系人的全名,但我什么也没得到。

$xml = "<?xml version='1.0' encoding='utf-8'?>"
$xml += "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"
$xml += "<soap:Body>"
$xml += "<Retrieve xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services'>"
$xml += "<entityName>contact</entityName>"
$xml += "<id>12345678-1234-1234-1234-123456789012</id>"
$xml += "<columnSet xmlns:q1='http://schemas.microsoft.com/xrm/2011/Contracts' xsi:type='q1:ColumnSet'>"
$xml += "<q1:Attributes>"
$xml += "<q1:Attribute>fullname</q1:Attribute>"
$xml += "<q1:Attribute>telephone1</q1:Attribute>"
$xml += "</q1:Attributes>"
$xml += "</columnSet>"
$xml += "</Retrieve></soap:Body></soap:Envelope>"

$url="http://crmserver.company.com/Organization/XRMServices/2011/Organization.svc/web"
$http_request = New-Object -ComObject Msxml2.XMLHTTP
$http_request.Open('POST', $url, $false)
$http_request.setRequestHeader("SOAPAction",     "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Retrieve");
$http_request.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
$http_request.setRequestHeader("Content-Length", $xml.length);
$http_request.send($xml);
$http_request.responseText

这是回复:

$http_request.responseText

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body><RetrieveResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
<RetrieveResult xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Attributes xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<a:KeyValuePairOfstringanyType>
<b:key>accountid</b:key>
<b:value i:type="c:guid" xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/">12345678-1234-1234-1234-123456789012</b:value>
</a:KeyValuePairOfstringanyType>
</a:Attributes>
<a:EntityState i:nil="true"/><a:FormattedValues xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
<a:Id>12345678-1234-1234-1234-123456789012</a:Id><a:LogicalName>account</a:LogicalName>
<a:RelatedEntities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
</RetrieveResult>
</RetrieveResponse>

我只是不知道我做错了什么。为什么代码不返回“fullname”,它在列集中?

最佳答案

尝试修改您的请求的这一部分:

$xml += "<columnSet xmlns:q1='http://schemas.microsoft.com/xrm/2011/Contracts' xsi:type='q1:ColumnSet'>"
$xml += "<q1:Columns xmlns:c='http://schemas.microsoft.com/2003/10/Serialization/Arrays'>"
$xml += "<c:string>fullname</c:string>"
$xml += "<c:string>telephone1</c:string>"
$xml += "</q1:Columns>"

您可以在此处查看其他一些 SOAP 示例: http://code.msdn.microsoft.com/CRM-Online-2011-WebServices-14913a16

关于powershell - 使用 PowerShell 查询 CRM 2011 SOAP 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10501209/

相关文章:

javascript - CRM 2011 RollUp 12 刷新网格

javascript - Dynamics CRM根据父表单/实体在新表单/实体中填充关系数据

javascript - FormType 未在 Dynamics CRM 2016 上返回正确的值

c# - 实体记录已创建,但查找字段保持为空

c# - 如何将 LINQ 查询限制为给定营销事件的营销列表?

c# - 带有 PartyList 的 QueryExpression 中的错误

.net - 如何在 Visual Studio 中调试 Windows PowerShell 模块?

powershell - 重命名项认为变量是一个路径

powershell - 为什么将 "switch"类型参数的值传递给字符串参数?

powershell - 使用 PowerShell 作为 WebStorm 终端并在当前项目文件夹中打开