2

I am trying to integrate AddressDoctor with my Salesforce App. Below is the service I am using. AddressDoctor Webservice Validator and description

The service needs the request to be in format of <soap:body>..... </soap:body> but the Apex class which was converted from WSDL using wsdl2Apex is creating the request string in <env:body>... </env:body> format, due to which the response is coming as "Input String was not in correct format". I did some research and found out that soap and env are actually different tags, so I am doubting this as the culprit of this issue. How can I prepare the request string in the correct format? Has anyone faced this issue before? Any help would be appreciated.

Below is the error I am receiving from the call out.

System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (1, 380). ---> System.FormatException: Input string was not in a correct format.

2

I tried calling the same web service using Apex generated using the FuseIT SFDC Explorer (full disclosure, I work for the FuseIT). In theory the results should be the same as the built in Wsdl2Apex implementation, but it could also account for some differences.

After adding the Remote Site Settings for http://validator2.addressdoctor.com I tried the following minimal anonymous Apex:

validator2AddressdoctorComAddbatchB.BatchSoap bs = new validator2AddressdoctorComAddbatchB.BatchSoap();
validator2AddressdoctorComAddbatchB.addBatchRequest addBatchRequest = new validator2AddressdoctorComAddbatchB.addBatchRequest();
bs.Validate(addBatchRequest);

This gave the error:

System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (1, 334). ---> System.FormatException: Input string was not in a correct format.

I found the debug log showed the full error message in the CALLOUT_RESPONSE:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <soap:Fault>
      <faultcode>soap:Client</faultcode>
      <faultstring>System.Web.Services.Protocols.SoapException: Server was unable to read request. ---&gt; System.InvalidOperationException: There is an error in XML document (1, 334). ---&gt; System.FormatException: Input string was not in a correct format.
   at System.Number.ParseInt64(String s, NumberStyles style, NumberFormatInfo info)
   at System.Xml.XmlConvert.ToInt64(String s)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read1_addBatchRequest(Boolean isNullable, Boolean checkType)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read19_Validate()
   at Microsoft.Xml.Serialization.GeneratedAssembly.ValidateSerializer.Deserialize(XmlSerializationReader reader)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
   at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
   --- End of inner exception stack trace ---
   at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
   at System.Web.Services.Protocols.WebServiceHandler.Invoke()
   at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()</faultstring>
      <detail />
    </soap:Fault>
  </soap:Body>
</soap:Envelope>

Looks like it was expecting a long (Int64) in the request. From the addBatchRequest element that would most likely be the AddressCount. So I tried the request:

validator2AddressdoctorComAddbatchB.BatchSoap bs = new validator2AddressdoctorComAddbatchB.BatchSoap();
validator2AddressdoctorComAddbatchB.addBatchRequest addBatchRequest = new validator2AddressdoctorComAddbatchB.addBatchRequest();
addBatchRequest.AddressCount = 0;
bs.Validate(addBatchRequest);

That gave me a ValidateResponse in the CALLOUT_RESPONSE. Admittedly that contained the ErrorCode 201, but the web service was called and sent a response.

By the way, that web service shouldn't be returning stack traces for errors. It would make it easier for hacker types to figure out what is going on.

0

I was able to fix this. The issue was with the address I was providing and AddressCount variable was not set. Thanks Daniel, good catch!

And turns out even though my request body is having the format <env:body>... </env:body, it still accepts the input string. The tags were not the culprit, may be I was(ha ha!).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.