I need to send an image to a SOAP web service implemented in PHP.
The WSDL for the service looks like this…
<xsd:complexType name="Product">
<xsd:all>
<xsd:element name="ProductId" type="xsd:int"/>
<xsd:element name="Image01" type="xsd:base64Array"/>
</xsd:all>
</xsd:complexType>
When I reference this service in my C# application the data type used for Image01 is String.
How can I get an image from disk and send encode it in the correct way to send it via this complex type?
Would appreciate sample code.
Load the image up into a
byte[]type then run it through aConvert.ToBase64String()There’s a nice sample of code on this question to load a file from disk into a byte[]
So you’d just do
And pass that back via the web service call. I’ve avoided using the
Image.FromFilecall so you can re-use this example with other non image calls to send binary information over a webservice. But if you wish to only ever use an Image then substitute this block of code for anImage.FromFile()command.