How to post a value from VB.NET to a web service?

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 1747 Views - Last Post: 27 August 2015 - 06:50 AM Rate Topic: -----

#1 savedlema  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 56
  • Joined: 19-June 13

How to post a value from VB.NET to a web service?

Posted 09 June 2015 - 02:47 PM

Hi all!

This article, explain how to create a web service and use it from VB.NET, but it does not show I can post a value from VB.NET form and use that value in the web service, like in the WHERE clause of a db selection string found inside the web service php script.

So I would like for someone to guide me on this:
-- I have a text box in a VB. NET form (VS 2013)
-- On the form, I have a textbox with a text "4560" on it.
-- I have a web service that runs well which I created from the tutorial I linked above.
-- This webservice is made on php and inside it, there is a script for SELECTing some data from a mysql database.
-- This SELECT statement does not include a WHERE clause
-- I want to add my own WHERE clause to this code. I even tried to hardcode the WHERE value and it worked.
-- Now, I want to be able to pass a value from the VB.NET form to the service and then use that value in the WHERE clause.

I hope I make myself clear and can someone please help me on this?

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: How to post a value from VB.NET to a web service?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13965
  • View blog
  • Posts: 55,749
  • Joined: 12-June 08

Re: How to post a value from VB.NET to a web service?

Posted 09 June 2015 - 02:53 PM

In the initial example it showed how to get a parameter value in.. the "say_hello" method.. well, use that parameter logic a method to then use an incoming parameter in a WHERE clause for the SQL.
Was This Post Helpful? 0
  • +
  • -

#3 savedlema  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 56
  • Joined: 19-June 13

Re: How to post a value from VB.NET to a web service?

Posted 09 June 2015 - 07:58 PM

Thanks modi123....the writer of the thread which taught me how to work with a Web service.

I forgot to mention that I tried for time playing around with the first part you mentioned but I couldn't get it to hold the other values I wanted. Primarily because I couldn't understand how the script receive the value for "sName" from Vb.net.
I tried declaring a new variable like $ country = Say_Hello(sName);
but that didn't work.

I'll appreciate any further assistance please.

Thanks again for that tutorial.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13965
  • View blog
  • Posts: 55,749
  • Joined: 12-June 08

Re: How to post a value from VB.NET to a web service?

Posted 10 June 2015 - 06:40 AM

I am unclear what you are not getting.

In the PHP - this registers a function name and says it takes a parameter.
13	   $server->register('Say_Hello',// method name
14	        array('name' => 'xsd:string'),// input parameter called name.. and it's a string.



In the PHP - this shows the method signature in a very clear fashion. A function name, a parameter, and using that parameter. The stub from above is given substance.
24	    function Say_Hello($sName)
25	    {       
26	      return 'Hello ' . $sName . '!  Hello world!';
27	    }



In the VB.NEt this shows the function name and parameter operate like any other vb.net function.

10	        MsgBox(foo.Say_Hello(TextBox1.Text))



In the PHP - conversely - here is an example of function being registered that has zero parameters.
30	   $server->register('Get_Test_Data',// method name
31	        array(),// input parameter - nothing!


In the PHP - here is that stub given substance.
41	    function Get_Test_Data()
42	    {



In the PHP - here is where you would want to add a 'WHERE' clause that would use a parameter.
51	                $sql = "SELECT lId
52	                ,sValue
53	                ,sText
54	                FROM test_table ";


In the VB.NEt this shows the function name operates like any other vb.net function.
11	        bar = foo.Get_Test_Data()



I show two different ways to have the php declare a function - one with and one without a parameter. In one I show how to use a php parameter. In both I show how the VB.NET code uses both php functions like any ol' vb.net function.

It should not be too large of a leap to take the knowledge from both examples and combine them into a function, that takes a parameter, and uses it in a database SELECT statement's WHERE clause.
Was This Post Helpful? 0
  • +
  • -

#5 savedlema  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 56
  • Joined: 19-June 13

Re: How to post a value from VB.NET to a web service?

Posted 15 June 2015 - 02:18 PM

Thank you again modi123_1,
Sorry for my slow catching on this one, I'm not so proficient with php. I'm usually a VB.NET guy.

I managed to deal with the SELECT command and its working perfect now.

Now I want to do an UPDATE to the database from this service. I want to pass the values to be updated and insert an UPDATE statement in the service that will update the same database table.

Forgive me; I tried to replace the SELECT statement with an UPDATE statement and removed all the "result" queries but I could not get my table updated.

Also, I looked up the code when the methods were created, it seems they were created specifically to receive the result of a select query (such as the presence of MyTableData)...

If you can guide me, or make another tutorial which updates data to a database, I will appreciate.

Thanks so far,
Frank.


[quote name='modi123_1' date='10 June 2015 - 06:40 AM' timestamp='1433943630' post='2159889']
I am unclear what you are not getting.

In the PHP - this registers a function name and says it takes a parameter.
13	   $server->register('Say_Hello',// method name
14	        array('name' => 'xsd:string'),// input parameter called name.. and it's a string.

Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13965
  • View blog
  • Posts: 55,749
  • Joined: 12-June 08

Re: How to post a value from VB.NET to a web service?

Posted 15 June 2015 - 02:29 PM

Have you looked at how PHP does database interactions? I would strongly urge starting there.
Was This Post Helpful? 0
  • +
  • -

#7 savedlema  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 56
  • Joined: 19-June 13

Re: How to post a value from VB.NET to a web service?

Posted 15 June 2015 - 02:38 PM

Yes, I have been to this page, http://www.w3schools...ysql_update.asp and some few others. It's not a problem getting the UDPATE statement. But I can't get it to work.

$conn = mysql_connect('localhost', 'username', 'password')
				or die('Could not connect: ' . mysql_error());
				
				// make our database point to your 'test' database. 
				mysql_select_db('dbname') or die('Could not select database');        
				
				// a simple select statement.
				$sql = "UPDATE tablename SET cust_name = 'Mathew' WHERE email = '$test_email'";
    
	   			
          } 

Assuming that I don't need any echo-ing by now, just the update.

This brings the error "The request failed with an empty response". I know there is a mess somewhere but I'm unable to figure it out.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13965
  • View blog
  • Posts: 55,749
  • Joined: 12-June 08

Re: How to post a value from VB.NET to a web service?

Posted 15 June 2015 - 02:48 PM

Do you a a problem? You are not showing where the sql statement is EXECUTEd.
Was This Post Helpful? 0
  • +
  • -

#9 savedlema  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 56
  • Joined: 19-June 13

Re: How to post a value from VB.NET to a web service?

Posted 15 June 2015 - 02:58 PM

Lol!Guide me with some php please
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13965
  • View blog
  • Posts: 55,749
  • Joined: 12-June 08

Re: How to post a value from VB.NET to a web service?

Posted 15 June 2015 - 03:53 PM

Man, you gotta be able to read the clearly written tutorials and understand what is going on. Excessive hand holding or giving you the code will not help you with understanding.
Was This Post Helpful? 0
  • +
  • -

#11 savedlema  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 56
  • Joined: 19-June 13

Re: How to post a value from VB.NET to a web service?

Posted 16 June 2015 - 03:17 PM

Right.

This php code will work if I use on just a simple php page:

$cust_name = "Mathew John";
$email = "[email protected]";

$username="usernamehere";
$password="dbpassword";
$database="dbnamehere";
mysql_connect(localhost,$username,$password);
mysql_select_db('dbnamehere') or die('Could not select database'); 


$query="UPDATE dbname SET cust_name='$cust_name' WHERE email='$email'" or die(mysql_error());  

mysql_query($query);
echo "Record Updated";
mysql_close();


But when I used it in the service I get the error: "You must provide an array for operational inputs"

I did a Google search for that error and there was nothing really informative and specific to web services/NUSOAP

Why the error please?
Regards.
Was This Post Helpful? 0
  • +
  • -

#12 savedlema  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 56
  • Joined: 19-June 13

Re: How to post a value from VB.NET to a web service?

Posted 16 June 2015 - 03:37 PM

Is that a php error or a NUSOAP/service error?
Was This Post Helpful? 0
  • +
  • -

#13 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13965
  • View blog
  • Posts: 55,749
  • Joined: 12-June 08

Re: How to post a value from VB.NET to a web service?

Posted 16 June 2015 - 04:00 PM

I am not sure what you are doing there. Again - in my example I show how you need ot register the name, register the parameter list, and then have a method (with the registered name) with the right parameter list you registered.
Was This Post Helpful? 0
  • +
  • -

#14 savedlema  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 56
  • Joined: 19-June 13

Re: How to post a value from VB.NET to a web service?

Posted 17 June 2015 - 02:08 AM

Thank you for your nice tutorial which has introduced me to web services and how they can be consumed from VB.NET

Best regards.
Was This Post Helpful? 0
  • +
  • -

#15 savedlema  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 56
  • Joined: 19-June 13

Re: How to post a value from VB.NET to a web service?

Posted 27 August 2015 - 06:37 AM

View Postmodi123_1, on 16 June 2015 - 04:00 PM, said:

I am not sure what you are doing there. Again - in my example I show how you need ot register the name, register the parameter list, and then have a method (with the registered name) with the right parameter list you registered.


Hi modi123_1, I'm here for a feedback; shortly after these posts, from your instructions, I was able to create my own web service (for the first time) and consume it from VB.Net application very nicely. Thank you very much, very much for your tutorial and tutoring. God bless!
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2