Passing binary data to a web service method using XMLHttp from VBA code

G

gagans

Hi
My web service has a method which accepts byte array as parameter.
<WebMethod()> _
Public Function SendLoan(ByVal data As Byte()) As String
Dim filePath As String
filePath = System.AppDomain.CurrentDomain.BaseDirectory() &
"\WorkingFiles\"
objImportExport = New BrainImportExport.BrainImportExport
SendLoan = objImportExport.ImportLoanByLoan(data, filePath)
objImportExport = Nothing
End Function

I am calling this function from VBA client. Following is the code

Dim arr1() As Byte
ReDim arr1(Len("Data=" & xmlDoc.xml))
arr1 = StrConv(("Data=" & xmlDoc.xml), vbFromUnicode)

Dim objXMLHTTP As New MSXML2.XMLHTTP30
Dim strResponse As String
Dim strURL As String 'Web service url
strURL = "http://localhost/brainwebservices/brainwebservices.asmx/SendLoan"
objXMLHTTP.Open "POST", strURL, True
objXMLHTTP.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
objXMLHTTP.setRequestHeader "Content-Length", UBound(arr1)


'Call web service and pass its parameters
objXMLHTTP.send arr1
'>>> Loop until the call comes back
Do Until objXMLHTTP.readyState = 4
DoEvents
Loop
'When exiting the loop, get the response from the webservice
strResponse = objXMLHTTP.responseText
If objXMLHTTP.statusText = "OK" Then
MsgBox "Data sent to web services successfully"
Else
MsgBox "Error in sending data to web services"
End If


I am getting following error:
System.ArgumentException: Cannot convert to System.Byte.
Parameter name: type ---> System.FormatException: Input string was not
in a correct format.
at System.Number.ParseInt32(String s, NumberStyles style,
NumberFormatInfo info)
at System.Byte.Parse(String s, NumberStyles style, IFormatProvider
provider)
at System.String.System.IConvertible.ToByte(IFormatProvider
provider)
at System.Convert.ChangeType(Object value, Type conversionType,
IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType)
at System.Web.Services.Protocols.ScalarFormatter.FromString(String
value, Type type)
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.ScalarFormatter.FromString(String
value, Type type)
at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection
collection)
at System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest
request)
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()


Earlier i was using SOAP Toolkit 3.0.It was working fine.
Please let me know if am missing anything.

Thanks in advance
Regards
gagan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top