Can't make parameter optional

R

Ronald S. Cook

In my service project I have this function:

Public Function SelectPenTypeTest(Optional ByVal PenTypeID As String =
Nothing) As String Implements IPen.SelectPenTypeTest
If PenTypeID = String.Empty Then
Return "You didn't pass anything"
Else
Return "You passed: " + PenTypeID
End If
End Function

I then generate the proxy class and include it in my client project.

However, in the client I am required to put either a string value or
Nothing.

Dim _Pen As New PenClient()
Dim TempString As String = _Pen.SelectPenTypeTest(Nothing)

I would much rather be able to just put the following when I don't want to
pass a value:

Dim TempString As String = _Pen.SelectPenTypeTest()

What am I doing wrong? Is it because I have Option Strict and Option
Explicit set to On? Something else?

I looked inside the generated proxy class for Pen and part of it looks like
this:

'CODEGEN: Parameter 'SelectPenResult' requires additional schema information
that cannot be captured using the parameter mode. The specific attribute is
'System.Xml.Serialization.XmlElementAttribute'.
<System.ServiceModel.OperationContractAttribute(Action:="http://tempuri.org/IPen/SelectPen",
ReplyAction:="http://tempuri.org/IPen/SelectPenResponse"), _
System.ServiceModel.XmlSerializerFormatAttribute()> _
Function SelectPen(ByVal request As SelectPenRequest) As SelectPenResponse

I don't know if it means anything that there's no "Optional" in front of
ByVal or what.

Thanks for any help,
Ron
 
A

Andrew Morton

Ronald said:
In my service project I have this function:

Public Function SelectPenTypeTest(Optional ByVal PenTypeID As String =
Nothing) As String Implements IPen.SelectPenTypeTest
If PenTypeID = String.Empty Then
Return "You didn't pass anything"
Else
Return "You passed: " + PenTypeID
End If
End Function

Isn't the preferred way of doing it to overload the function? Does trying
that make it work the way you want?

Andrew
 
R

Ronald S. Cook

I can't seem to make an overload work in this scernario (WCF). While my
serice project will build, I can't generate the proxy class. It simply
won't generate. -thx
 

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