Hi,
We are trying to integrate via Customer Information Manager (CIM). We have a code written in transact SQL (MS SQL Server 2000) using .NET objects, which sends the XML but we are receiving the same error all the time (Root element is missing.) We know that there are better ways to accomplish it (asp.net page, etc) but now we need specifically to do it via SQL Server. We know this is a very particular scenario but maybe someone can give us any idea.
We have changed the code to try in different ways but all the time we get the same error. We appreciate any help. This is the code:
declare @strXML varchar(8000)
select @strXML =
'<?xml version="1.0" encoding="utf-8"?>
<createCustomerProfileTransactionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>xxx</name>
<transactionKey>yyy</transactionKey>
</merchantAuthentication>
<transaction>
<profileTransAuthOnly>
<amount>34</amount>
<shipping>
<amount>0.00</amount>
<name>free shipping</name>
<description>Free ground based 5 to 10 day shipping</description>
</shipping>
<lineItems>
<itemId>ITEM00001</itemId>
<name>name of item sold</name>
<description>Description of item sold</description>
<quantity>1</quantity>
<unitPrice>32</unitPrice>
<taxable>true</taxable>
</lineItems>
<customerProfileId>11111</customerProfileId>
<customerPaymentProfileId>22222</customerPaymentProfileId>
<customerShippingAddressId>33333</customerShippingAddressId>
<order>
<invoiceNumber>INV000001</invoiceNumber>
<description>description of transaction</description>
</order>
</profileTransAuthOnly>
</transaction>
</createCustomerProfileTransactionRequest>'
Declare @Url as Varchar(8000)
select @Url = 'https://apitest.authorize.net/xml/v1/request.api'
Declare @Object as Int;
Declare @ResponseText as Varchar(8000);
--==
--Build XML
Declare @objXML int
Exec sp_OACreate 'MSXML2.DOMDocument' , @objXML OUT
Exec sp_OASetProperty @objXML, 'async', 'false'
Exec sp_OAMethod @objXML, 'loadXML', NULL, @strXML
--==
Exec sp_OACreate 'MSXML2.ServerXMLHTTP', @Object OUT--, 4
Exec sp_OAMethod @Object, 'open', NULL, 'POST', @Url, 'false'
Exec sp_OAMethod @Object, 'setRequestHeader', NULL, 'Content-Type' ,'text/xml'
Exec sp_OAMethod @Object, 'send', NULL, @objXML
Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
select @ResponseText
/*
Error received:
<?xml version="1.0" encoding="utf-8"?><ErrorResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><messages><resultCode>Error</resultCode><message><code>E00003</code><text>Root element is missing.</text></message></messages></ErrorResponse>
*/
Thanks in advance.
09-25-2011 08:09 PM
What the @objXML look like before you send it?
Also, did you look at the CIM - ASP Classic sample code? It look very similar except it send the @strXML directly without convert it to a MSXML2.DOMDocument first before sending it(util.asp).
09-26-2011 04:38 AM
Yes, we looked the asp classic sample and we tried sending the string directly but get the same error...
09-26-2011 08:41 PM
Try adding Content-Length RequestHeader and send@strXML directly without convert it to a DOMDocument
declare @strXMLLength nvarchar(8)
set @strXMLLength = len(@strXML)
EXEC sp_OAMethod @Object, 'setRequestHeader', NULL, 'Content-Length', @strXMLLength
09-27-2011 05:25 AM - edited 09-27-2011 05:25 AM