Solved

c# to vb.net conversion error.

Posted on 2013-05-25
7
491 Views
Last Modified: 2013-09-24
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
Comment
Question by:jamppi
  • 3
  • 3
7 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39196858
which line throws the exception?
0
 

Author Comment

by:jamppi
ID: 39197145
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
 
LVL 42

Expert Comment

by:sedgwick
ID: 39197346
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jamppi
ID: 39197932
Hi!  

The c# code runs just fine.  

For some strange reason EE wont let me publish the zipped vb.net conversion solution.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39198175
Change the extension ofthe zip file  to .txt and u would be able to post it here
0
 

Author Comment

by:jamppi
ID: 39199262
nope. it wont accept it.
it's on my google drive
https://docs.google.com/file/d/0B9bl-Tcr6AP5N1N1OHlGblF5M00/edit
0
 
LVL 12

Accepted Solution

by:
jitendra patil earned 500 total points
ID: 39204351
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now