【问题标题】:Microsoft Dynamics CRM 2013: ADD via SOAP/PHP - XML structure issueMicrosoft Dynamics CRM 2013:通过 SOAP/PHP 添加 - XML 结构问题
【发布时间】:2015-08-11 20:04:15
【问题描述】:

Microsoft Dynamics CRM 这些天让我发疯了(遗憾的是,我对这些东西完全陌生)。我正在尝试通过 PHP/SOAP 向 Microsoft Dynamics CRM 2013 帐户实体添加新记录,但我一直没有得到任何答案。根据Campey's blog ADD xml 请求正文应该包含这样的“创建”标签

<create xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
    <entity xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
      <a:attributes xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
  <!-- ATTRIBUTE XML GOES HERE!! -->
      </a:attributes>
      <a:entitystate i:nil="true">
      <a:formattedvalues xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
      <a:id>00000000-0000-0000-0000-000000000000</a:id>
      <a:logicalname><!-- ENTITY NAME GOES HERE!! --></a:logicalname>
      <a:relatedentities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
    </a:relatedentities></a:formattedvalues></a:entitystate></entity>
</create>

我已经有一个使用“请求”标签下载项目列表的工作脚本,所以我确信“标题”部分可以正常工作,我可以专注于“s:Body”。 我将 Campey 的示例 sn-p 放在“Execute->request”标签中,如下所示。但这会导致我出错。 似乎已连接到请求标记 xmlns 属性,但不确定。提前感谢您的宝贵帮助!

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:request. 

The InnerException message was 'Error in line 2 position 38. 

Element 'http://schemas.microsoft.com/xrm/2011/Contracts/Services:request' contains data from a type that maps to the name 'http://www.w3.org/2005/08/addressing:CreateRequest'. 

The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'CreateRequest' and namespace 'http://www.w3.org/2005/08/addressing'.'. Please see InnerException for more detail

XML 结构

<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <request i:type="a:CreateRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">

            <create xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">

            <entity xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
      <a:attributes xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
 <a:keyvaluepairofstringanytype>
                                <b:key>name</b:key>
                                <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">aaa-test</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>00000000-0000-0000-0000-000000000000</a:id>
      <a:logicalname>account</a:logicalname>
      <a:relatedentities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
    </a:relatedentities></a:formattedvalues></a:entitystate></entity>
</create>
    </request>
        </Execute>

[解决方案] WTF 数小时后更新 我仍然不知道为什么,但我不得不删除“创建”标签并只使用执行->请求。一旦我放置了一个带有 CreateRequest 类型的“请求”标签,它就起作用了。这是其他人需要的代码。不确定从 CRM 2011 到 CRM 2013 的 XML 结构是否发生了变化,或者只是记录不充分。顺便说一句,非常感谢您的帮助!

<Execute xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
      <request i:type='a:CreateRequest' xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts'>
        <a:Parameters xmlns:b='http://schemas.datacontract.org/2004/07/System.Collections.Generic'>
          <a:KeyValuePairOfstringanyType>
            <b:key>Target</b:key>
            <b:value i:type='a:Entity'>
              <a:Attributes>
                <a:KeyValuePairOfstringanyType>
                  <b:key>name</b:key>
                  <b:value i:type='c:string' xmlns:c='http://www.w3.org/2001/XMLSchema'>test1234</b:value>
                </a:KeyValuePairOfstringanyType>
              </a:Attributes>
              <a:EntityState i:nil='true' />
              <a:FormattedValues />
              <a:Id>00000000-0000-0000-0000-000000000000</a:Id>
              <a:LogicalName>account</a:LogicalName>
              <a:RelatedEntities />
            </b:value>
          </a:KeyValuePairOfstringanyType>
        </a:Parameters>
        <a:RequestId i:nil='true' />
        <a:RequestName>Create</a:RequestName>
      </request>
    </Execute>

【问题讨论】:

  • 也许 StackOverflow 上的这个问题有帮助:stackoverflow.com/questions/17777810/…
  • Thanx Henk 但同样的问题,我在发布之前检查了该问题以查看我的 KeyValuePairOfstringanyType 标签是否正常,但它没有给我关于整个 xml 结构的任何线索。无论如何,我现在找到了解决方案。
  • 这很奇怪。你的目标到底是什么端点,organization.svc,organization.svc/web?

标签: php dynamics-crm dynamics-crm-2013


【解决方案1】:

看起来你很接近了!

删除 执行和请求行

您应该只需要&lt;create&gt; 区域 所以你的整个请求应该是这样的

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            HEADER GOES HERE
            <s:Body>
                <create xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">

            <entity xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
      <a:attributes xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
 <a:keyvaluepairofstringanytype>
                                <b:key>name</b:key>
                                <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">aaa-test</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>00000000-0000-0000-0000-000000000000</a:id>
      <a:logicalname>account</a:logicalname>
      <a:relatedentities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
    </a:relatedentities></a:formattedvalues></a:entitystate></entity>
</create>
            </s:Body>
        </s:Envelope>

【讨论】:

  • 遗憾的是,如果我尝试使用该结构,我会收到一个更一般的错误:“InternalServiceFaultThe server is unable to process the request due to an internal error.”
  • 最后我解决了,谢谢你的帮助。听起来很奇怪,但我不得不使用请求参数(带有 CreateRequest 类型)而不是创建。如果我阅读指南,这是没有意义的。从 2011 年到 2013 年,XML 结构可能发生了变化,不知道。如果其他人有同样的问题,我会更新我的第一篇文章。
猜你喜欢
  • 2015-04-24
  • 2014-03-07
  • 2016-03-11
  • 1970-01-01
  • 2013-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-01
相关资源
最近更新 更多