Microsoft Dynamics CRM 2013:通过SOAP / PHP添加 - XML结构问题

时间:2015-08-10 15:37:35

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

Microsoft Dynamics CRM这些天让我疯狂(遗憾的是,我对这些东西完全不熟悉)。我试图通过PHP / SOAP将新记录添加到Microsoft Dynamics CRM 2013帐户实体,但我一直没有得到答案。根据{{​​3}} 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>

我已经有一个工作脚本使用&#34; request&#34;下载项目列表标签,所以我相信&#34; Header&#34;部分是完全正常的,我可以专注于&#34; s:Body&#34;。 我把Campey的示例代码段放在&#34; Execute-&gt; request&#34;标签,如下。但这会导致我的错误。 似乎已连接到请求标记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>

[解决方案]在WTFING之后更新 我仍然不知道为什么,但我必须删除&#34;创建&#34;标记并使用execute-&gt; request。一旦我发出了&#34;请求&#34;标签与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>

1 个答案:

答案 0 :(得分:1)

看起来你已经关闭了!

删除 执行和请求行

您应该只需要<create>区域 所以你的整个请求应该是

<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>