function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Attempting to invoke an outside .NET WCF Service

I have an external .NET WCF Service that I am trying to invoke from outside the Salesforce sandbox.  One of the arguments in the .NET WCF Service function call is a byte array.  What is the appropriate conversion in APEX so that I can pass data to this function?


WSDL element:

<xs:elementminOccurs="0"name="FileContents"nillable="true"type="xs:base64Binary" />



Call to this:

String filecontents = BuildFile();
inputfile.FileName = 'SalesForceAddressFile.txt';
inputfile.FileContents = EncodingUtil.base64Encode(Blob.valueOf(filecontents));


When I look at the DataContract that was pulled in, the property is a String, but defined to the service as base64Binary.


Here is the DataContract code that was generated from the WSDL:

    public class FileObject {
        public String FileContents;
        public String FileName;
        private String[] FileContents_type_info = new String[]{'FileContents','','base64Binary','0','1','true'};
        private String[] FileName_type_info = new String[]{'FileName','','string','0','1','true'};
        private String[] apex_schema_type_info = new String[]{'','true','false'};
        private String[] field_order_type_info = new String[]{'FileContents','FileName'};





But when I invoke the webservice, there is an error thrown and I have narrowed it down to this property.  What am I doing wrong?  I have UnitTests setup in an external program that test the web service outside of the call from SalesForce, so I know that the webservice functions properly.  If I set inputfile.FileContents to null, I can get from SalesForce to the web service and execute the web service method.  When I keep the code as above, and send a String using the EncodingUtil, it errors on the invoking of the web service method.


just do Blob.valueOf(filecontents)


A Blob.valueOf(filecontents) will not work, won't compile, because when the class is generated from the wsdl, inputfile.FileContents is a String.