Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consuming web services in VB.NET

I am testing web services in .NET for the first time. I am almost there, but I can't seem to consume the web service. I know this post is similar to about 5-6 other posts on this site, but I have reviewed them, and still can't get the syntax correct.

So far, I have: -Create a simple web service that creates a directory -Worked in development environment, but took some trouble shooting to get to work on live server -I can pull up the "automagically" generated .NET we service page. -Added web service reference - can now see the reference in my solution explorer and in intellisense.

Update: Here is a link to the webservice itself: http://67.78.188.50/Jservices/Service1.asmx

The web service accepts a string (name of directory e.g /test/directory). However, when I enter the name of the Web Reference (ServiceReference1) - I don't get the methods I expect...

Here are my options with the ServiceReference1 Object...

ServiceReference1.makeDirRequest
ServiceReference1.makeDirRequestBody
ServiceReference1.makeDirResponse
ServiceReference1.makeDirResponseBody
ServiceReference1.Service1Soap
ServiceReference1.Service1SoapChannel
ServiceReference1.Service1SoapClient
like image 739
tpow Avatar asked Feb 19 '10 15:02

tpow


2 Answers

Pass, you haven't posted enough code to see what you have done

I would strongly recommend that your use WCF

Given your sample names proved, you need

Dim service As New ServiceReference1.Service1SoapClient
service.makeDir("some val")

Download one of the many samples on the web (plenty on codeproject) and get the sample working first. If you cant get that to go then something else is wrong with you Windows installation

like image 160
TFD Avatar answered Sep 26 '22 01:09

TFD


I'm not sure that makeDirRequest is the service - that sounds like a message. Look for another type in that namespace (maybe ending in "service" or "client" if you are lucky, but ultimately named based on what you typed when using "add web reference" etc), that inherits from WebService.

This should have your service method(s) as public methods.


Having seen the service, I expect the problem is that you are adding a service-reference (WCF / 3.0) rather than a web-reference (2.0). If you are targetting 3.0 / 3.5, you can add a web-reference by using the "Advanced..." => "Add Web Reference" option (in the "Add Service Reference" dialog). Then you can use (where WebReference is whatever you named it when adding the reference):

Using client As WebReference.Service1 = New WebReference.Service1
    Dim foo As String = "foo"
    client.makeDir(foo)
End Using

If you instead use a WCF service-reference, then the name tends to include the "Soap" overhead (where ServiceReference1 is whatever you named it when adding the reference):

Using client As ServiceReference1.Service1SoapClient = New ServiceReference1.Service1SoapClient
    Dim foo As String = "foo"
    client.makeDir(foo)
End Using

Either way, it should work the same.

like image 21
Marc Gravell Avatar answered Sep 24 '22 01:09

Marc Gravell