Developer forum

Forum » Integration » XML error when sending a request to Live Int

XML error when sending a request to Live Int

Fredrik
Fredrik
Reply

I try to get live prices but get a error that says:

"Fjärrservern returnerade ett fel: (500) Internt serverfel. Response: The following exception was encountered when processing XML data: 'Data at the root level is invalid. Line 6, position 5.' at line 6 and position 5."

The request I send is:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><Process xmlns="urn:microsoft-dynamics-schemas/codeunit/DWWebService"><request>
<GetEcomData ExternalUserId="KT000002" AccessUserCustomerNumber="10000">
 <tables>
  <Products type="filter" unitPrices="true">
   <Product>
    <ProductId>PROD144</ProductId>
    <ProductVariantId></ProductVariantId>
    <ProductNumber>100795</ProductNumber>       
    <ProductIdentifier>100795..LANG1</ProductIdentifier> 
    <CurrencyCode>SE</CurrencyCode>
    <Quantity>1</Quantity>
   </Product>
  </Products>
 </tables>
</GetEcomData>
</request></Process></s:Body></s:Envelope>

The code I use is:

        private double GetLivePriceFromBc2(Product product, User user)
        {
            try
            {
                Endpoint endPoint = _endpointService.GetEndpointById(1);
                endPoint.AuthenticationId = 4;
                endPoint.Body = _endpointService.GetDynamicwebServiceSoapBody(endPoint, BuildSoapForPriceRequest(product, user));
                endPoint.Body = HttpUtility.HtmlDecode(endPoint.Body);
                endPoint.RequestType = EndpointRequestType.POST;
                var response = _endpointService.Execute(endPoint);
                XDocument responseXDocument = XDocument.Parse(response);
                return 0;
            }
            catch (Exception ex)
            {
                Logger.Log($"GetLivePriceFromBc2() " + ex.Message);
                return 0;
            }
        }
        private string BuildSoapForPriceRequest(Product product, User user)
        {
            try
            {
                return $@"
<GetEcomData ExternalUserId=""{user.ExternalID}"" AccessUserCustomerNumber=""{user.CustomerNumber}"">
 <tables>
  <Products type=""filter"" unitPrices=""true"">
   <Product>
    <ProductId>{product.Id}</ProductId>
    <ProductVariantId>{product.VariantId}</ProductVariantId>
    <ProductNumber>{product.Number}</ProductNumber>       
    <ProductIdentifier>{product.Number}..{product.LanguageId}</ProductIdentifier> 
    <CurrencyCode>SE</CurrencyCode>
    <Quantity>1</Quantity>
   </Product>
  </Products>
 </tables>
</GetEcomData>
";
            }
            catch (Exception ex)
            {
                Logger.Log("BuildSoapForPriceRequest() " + ex.Message);
                return "";
            }
        }
 
What am I doing wrong?
 
Best regards,
Fredrik

Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply
This post has been marked as an answer

Hi Fredrik,
it looks like the soap body content is wrong formatted, try this:
make your endpoint as Dynamicweb service endpoint in Dynamicweb admin endpoint management.
And use then this code instead:
Endpoint e = _endpointService.GetEndpointById(1);
var response = EndpointService.Execute(e.Id, EndpointService.GetDynamicwebServiceSoapBody(e, BuildSoapForPriceRequest(product, user)));

XDocument responseXDocument = XDocument.Parse(response);
BR, Dmitrij

Votes for this answer: 1
 
Fredrik
Fredrik
Reply

Hello

Thank you very much, it works now :)

Best regards,

Fredrik

 

You must be logged in to post in the forum