[英]Microsoft Dynamics CRM 2013: ADD via SOAP/PHP - XML structure issue
如今,Microsoft Dynamics CRM使我發瘋(可悲的是,我對這些東西是完全陌生的)。 我正在嘗試通過PHP / SOAP將新記錄添加到Microsoft Dynamics CRM 2013帳戶實體,但是我一直沒有得到任何答案。 根據Campey的博客 ,ADD xml請求主體應包含這樣的“ create”標簽
<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>
我已經有一個使用“ request”標簽的可下載項目列表的腳本,因此我可以肯定“ Header”部分可以正常工作,並且我可以專注於“ s:Body”。 我將Campey的示例代碼片段放入“ 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>
[解決方案] WTFing之后的幾小時更新我仍然不知道為什么,但是我不得不刪除“ create”標簽,而只使用execute-> request。 一旦我放置了帶有CreateRequest類型的“ request”標簽,它就起作用了。 這是萬一別人需要的代碼。 不知道XML結構是從CRM 2011更改為CRM 2013還是只是記錄不良。 順便說一句,thanx可以為您提供很多幫助!
<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>
看起來您已經接近了!
刪除執行和請求行
您只需要<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.