Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Consuming .net webservice with PHP

    hey guys,

    i have been searching the forums and have found some similar threads however my php knowledge is not that great so find it hard to adapt anything i have read to my exact situation.

    Simply all i want to do is consume a .net web service, all this service currently does is add two numbers and returns the result (for now anyway) . I have been given an example .net script to access this service but unfortunatly i need it in PHP.

    <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="utf-8" %>

    <script language="VB" runat="server">

    Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    If Not Page.IsPostBack then

    Dim testwebservice as new SimpleWSTest 'This is called via the proxy class in the app_code folder. You will need to do a similar thing in PHP i would think.

    lblresult.text = ws.AddNumbers(1,100)

    End If

    End Sub

    </script>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test consume web service</title>
    </head>
    <body>

    <p>this is a test web service accessed at MyDomain/testwebservices/addtwonumbers.asmx.</p>
    <p> Result:
    <asp:label runat=server id="lblresult" />
    </p>
    </body>
    </html>
    Im struggling to get a PHP equivalent of this script, however no doubt very simple, as mentioned i am fairly new to php consuming web services hence wouldnt know where to start.

    any help appreciated greatly,

    cheers


    dlyxzen

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You just need to know how to do this in php?
    You also need a form:
    PHP Code:
    <?php

    function addNums($num1$num2)
    {
        return 
    $num1 $num2;
    }

    if (isset(
    $_POST['submit']))
    {
        echo 
    "Product is: " addNums((float)$_POST['num1'], (float)$_POST['num2']);
    }

    ?>
    <form method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
      <fieldset>
        <label for="num1">Number 1:</label>
        <input type="text" name="num1" id="num1" />
        <label for="num2">Number 2:</label>
        <input type="text" name="num2" id="num2" />
      </fieldset>
      <fieldset>
        <input type="submit" name="submit" value="Add" />
      </fieldset>
    </form>
    This is sorta how you would do it. I cheaped out on error checking, but the easiest way to do that is to compare the typecasted input against the actual input to ensure the data is the same.
    Hope that helps!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •