[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 507
  • Last Modified:

c# to vb.net conversion error.

Hi!

i found this snippet from  
http://www.codeproject.com/Articles/166763/WCF-Streaming-Upload-Download-Files-Over-HTTP


It works fine when run as it is but when i convert it to vb.net
i get a strange  error saying that wrong parameters or return type
in System.ServiceModel.Channels.Message. it's not allowed to use other parameter types.

but it compiles just fine.

Public Function DownloadFile(request As DownloadRequest) As RemoteFileInfo _
        Implements IService.DownloadFile

        Dim result As New RemoteFileInfo()
        Try
            Dim filePath As String = System.IO.Path.Combine("c:\Uploadfiles", request.FileName)
            Dim fileInfo As New System.IO.FileInfo(filePath)

            ' check if exists
            If Not fileInfo.Exists Then
                Throw New System.IO.FileNotFoundException("File not found", request.FileName)
            End If

            ' open stream
            Dim stream As New System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)

            ' return result 
            result.FileName = request.FileName
            result.Length = fileInfo.Length
            result.FileByteStream = stream

        Catch ex As Exception
        End Try
        Return result

    End Function

Open in new window

0
jamppi
Asked:
jamppi
  • 3
  • 3
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
which line throws the exception?
0
 
jamppiAuthor Commented:
It doesnt point to any lite.

this is the error

The operation 'ProcessRequestForMessage' could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.

i dont se that i would do it in another way than iin the c# code.
0
 
Meir RivkinFull stack Software EngineerCommented:
this error is usually due to mixing message contracts with other contracts.
did u run it in C# code and it was working fine?
can u post the web.config?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
jamppiAuthor Commented:
Hi!  

The c# code runs just fine.  

For some strange reason EE wont let me publish the zipped vb.net conversion solution.
0
 
Meir RivkinFull stack Software EngineerCommented:
Change the extension ofthe zip file  to .txt and u would be able to post it here
0
 
jamppiAuthor Commented:
nope. it wont accept it.
it's on my google drive
https://docs.google.com/file/d/0B9bl-Tcr6AP5N1N1OHlGblF5M00/edit
0
 
Jitendra PatilSr.Software EngineerCommented:
hi jamppi,

I've tested your code you need a small change in your IService.vb

just Modifiy

Public Class DownloadRequest
    <MessageBodyMember()> _
    Public FileName As String
End Class

with

<MessageContract()>
Public Class DownloadRequest
    <MessageBodyMember()> _
    Public FileName As String
End Class


from the above change your service will start functioning.

Hope this helps.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now