gavin
gavin

Reputation: 1346

How to send files from soap lite client to wcf service?

I have a wcf service set up to accept basic http binding. I want to send an excel file from perl soap lite to my wcf service. What is the simpliest way to send this file? I was looking at mtom/mime, but they seem complicated and I don't know if soap lite uses mtom/mime. I was also thinking of using base64 string to encode the file first, then send it. If I use base64 encode, what datatype should I specify as the operation contract parameter?

Upvotes: 1

Views: 1192

Answers (2)

gavin
gavin

Reputation: 1346

MK. it turns out you are right. I used the below code to read in the file "in.xls" as binary into $data, then add it as a value in soap lite and it automatically tranformed into a byte[] on my wcf service.

open FHDL, "in.xls" or die $!;
binmode FHDL;
my ($buffer, $data, $n);
while (($n = read FHDL, $buffer, 4) != 0) {
    print "$n bytes read\n";
     $data .= $buffer ;
}
close FHDL;
$logisticOrder->attachment($data);

I just had to increase byte array size on my host.

<binding name="NetTcpBinding_ImageResizerServiceContract" closeTimeout="00:01:00" 
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
                transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" 
                hostNameComparisonMode="StrongWildcard" listenBacklog="10" 
                maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10" 
                maxReceivedMessageSize="2147483647"> 
                                <readerQuotas maxDepth="2147483647" 
                                                          maxStringContentLength="2147483647" 
                                                          maxArrayLength="2147483647" 
                                                          maxBytesPerRead="2147483647" 
                                                          maxNameTableCharCount="2147483647" /> 
                                <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
                        </binding>

Thank you

Upvotes: 1

MK.
MK.

Reputation: 34587

byte[] will be automatically base64 encoded and is the most robust and compatible way of sending binary attachments. I would not use anything esle unless I completely controlled both sides of conversation (and if I did always control both sides I wouldn't use SOAP).

Upvotes: 1

Related Questions