VB Web Service call error Object reference not set - vb.net

Hey all I am trying to figure out why I am getting the following error:
Object reference not set to an instance of an object.
on line 2 of code:
1. Dim HTPCws As HTPCWS.ServiceVB
2. Dim returned As String = HTPCws.DisplayMessageVB(what2send)
When I know what2send does have a value to send....
The Web Service code is this:
<WebMethod()> Public Function DisplayMessageVB(ByVal beingSent As String) As String
_strfromws = beingSent
Return "DONE"
End Function
What could I be forgetting?

HTPCws has not been instantiated. Change the code to:
Dim HTPCws = New HTPCWS.ServiceVB()
Dim returned As String = HTPCws.DisplayMessageVB(what2send)
Dim HTPCws As HTPCWS.ServiceVB declares a variable but does not assign it an object. Also the naming is a bit confusing. Better:
Dim service = New HTPCWS.ServiceVB()
Dim returned As String = service.DisplayMessageVB(what2send)

Related

How to read the returned complex object values when calling a method by reflection using 'Invoke' in VB.net

As you can see in the picture I see the return values from the call but I cannot use them.
How can I convert the return object to something else. This function is dynamic so I cannot use a reference object for this class.
Thank you!
I managed to read the object by using this
Dim oResults As Object = oMethod.Invoke(oUbCustomerService, oParameterValues)
For Each oResult in oResults
Dim oFieldInfoList() As FieldInfo = oResult.GetType().GetFields
dim strValue as String = oFieldInfoList(n).GetValue(oResult)
...
Next

WCF EF return as list

Hi I got the error when return EF as the list. Here are my codes.
WCF
Public Function GetMerchantList() As List(Of Merchant) Implements IMerchant.GetMerchantList
Dim ws As New aMerchantService.MerchantServiceClient
Dim General As New General
Dim kWSUrl As String = ""
Dim endpointAddress = ws.Endpoint.Address
Dim newEndpointAddress As New EndpointAddressBuilder(endpointAddress)
kWSUrl = General.ConvertWsURL("App")
newEndpointAddress.Uri = New Uri(kWSUrl & "MerchantService.svc")
ws = New aMerchantService.MerchantServiceClient("BasicHttpBinding_IMerchantService", newEndpointAddress.ToEndpointAddress())
Dim Data = ws.GetMerchantList()
Return Data
End Function
Merchant Class
Public Function GetMerchantList() As List(Of Merchant)
Dim Db As New TTMSEntities
Dim Data = (From p In Db.TT_MERCHANT Join r In Db.TT_BRANCH_SETTING On _
p.MERCHANT_BRANCH_INTERNAL_NUM Equals r.INTERNAL_NUM _
Select New Merchant With {.MerchantID = p.MERCHANT_ID,
.MerchantName = p.DESCRIPTION,
.BranchID = r.INTERNAL_NUM,
.BranchName = r.BRANCH_DESC})
If Data IsNot Nothing Then
Return Data.ToList
Else
Return Nothing
End If
End Function
The error is Error Value of type '1-dimensional array of
TTMS.App.WebSites.Data.Merchant' cannot be converted to
'System.Collections.Generic.List(Of TTMS.Web.WebSites.WCF.Merchant)'.
Please help. Thanks
It looks like you're using a service reference. By default, WCF will serialize generic lists as arrays. To override this behavior, when you go to add the service reference, click on the Advanced button at the bottom left corner. This will bring up the Service Reference Settings. Select System.Generics.List for the collection type (the default is System.Array):

Connecting to MongoDB through VB.NET 2010

I am attempting to connect to a MongoDB database:
Dim server As MongoServer = MongoServer.Create("mongodb://localhost")
Dim db As MongoDatabase = server("mydb")
Dim coll As MongoCollection = db("coll")
Dim query = New QueryDocument("name","sid")
Dim item As BsonDocument = coll.FindOneAs(query)
The last line throws an error, and reads:
Public Overridable function FindOneAs(documentType As System.Type)As Object': Value of type MongoDB.driver.queryDocument cannot be converted to System.Type
Now I know that the object passed here is most probably of Type, but then I am not able to proceed. What should I pass instead of QueryDocument to execute my query?
You should be using the static methods of the Query class, like EQ which means equals. The other operators for MongoDb are also located on that class. You can find the details here.
Dim server As MongoServer = MongoServer.Create("mongodb://localhost")
Dim db As MongoDatabase = server("mydb")
Dim coll As MongoCollection = db("coll")
Dim query = Query.EQ("name","sid")
Dim item As BsonDocument = coll.FindOneAs(query)

Using Value of String variable to call an instance in vb.net winform

I have UserControl named for example 'aaa'
then i have variable:
Dim a as String = "aaa"
Now, i declare
Dim uc as UserControl = new aaa
my question is, can i write declaration above using value of variable a like below
Dim uc as UserControl = new a
You can do this using reflection (in the System.Reflection) namespace. For instance:
Dim t As Type = Assembly.GetExecutingAssembly().GetType("namespace.aaa")
Dim o As Object = Activator.CreateInstance(t)
Notice that you will need the full type name, including the namespace, so you may need to concatenate that to your string, for instance:
Dim namespace As String = "MyNamespace"
Dim t As Type = Assembly.GetExecutingAssembly().GetType(namespace & "." & a)
Dim o As Object = Activator.CreateInstance(t)

Unable to solve error "reference to a non-shared member requires an object reference. vb.net "

I have the following code
Case "Formula_MDX"
Dim cubeid As String = Request("intCubeId")
Dim strDimCode As String = Request("strDimCode")
Dim strMdxFormula As String = Request("strMdxFormula")
Dim result As String
result = HostAnalytics.HostAnalyzer.HostAnalyzer.setSubstituteVarMDXType(cubeid, strDimCode, strMdxFormula)
Case Else
Response.Write("Invalid call")
End Select
that vb method returns data of type string.
I declared the result of the typed string. but it is showing on that vb method like
"reference to a non-shared member requires an object reference"
How to solve this? Did I make any other mistakes in this code?
Make an object of that type, and invoke the method on that
Dim ha As New HostAnalytics.HostAnalyzer.HostAnalyzer() 'Edit, need New
result = ha.setSubstituteVarMDXType(cubeid, strDimCode, strMdxFormula)