Hello, so im trying to send an metod that takes a class as input parameter with a bunch of variables.
I want to write in some textboxes in my php side of the program send them with my class and into a database.
but the database part is no problem i just need help sending the text from textboxes-->class-->thru Wcf -->c# program
*
Service1.cs

public class Service1 : IService1
{
    public string KundGrunduppgifter(Variables.Kunder Kund)
    {
        //kund.customerNumber to database
        //kund.customerDeliveryAdress to database
        //and etc etc...
        //check is input is wrong 
        //write errortext

        return errortext;
    }
}

*
*
*
*
IService1.cs

[ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string KundGrunduppgifter(Variables.Kunder Kund);

    }
    [DataContract]
    public class Variables
    {
        public class Kunder
        {
            [DataMember]
            //Kund Grunduppgifter variablar  
            public string KundNummer, KundOrgNummer, KundNamn, PostAdr, 
            PostAdr2, GLN, BesokAdr, Postnr, Ort, LandKod, Land, VATnr,
            Telefon, Telefon2, 

            public string Epost, Kundkat, Distrikt, Saljare, notes;
            public int cbKundSms, cbKundEpost;


            //Kund Fler Uppgifter variablar
            public string FuBetalningsVillk, FuLeveransVillk, 
            FuLeveransSatt, FuSpeditor, FuSprak, FuValuta, FuResenh, FuProjekt,
            public double FuFakturaRab, FuRadRab, FuKreditGrans;

            public int FuCb1Export, FuCb2EUkundMedVATnr, FuCb3Rantefakturering, 
            FuCb4Kravbrev, FuCb5KravAvgift, FuCb6RestnoteraEj,
            FuCb7ExpeditionsAvgift, FuCb8Frakt, FuCb9Samlingsfakturering,
            FuCb10overforAdressTillBestallning;
        }
    }

so my questions
1. Can i access my class directly or do i need to make an equal class with all the variables in php?
2. how do you make textboxes? in php/html
*
*
*

<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
<?php

        $client = new SoapClient("http://localhost:8731/phpwcf/?wsdl");

        class Customer
        {
            $CustomerNumber = textbox1.text
            $CustomerPhone = textbox2.text
            $CustomerName = textbox3.text
            $CustomerAdress = textbox4.text
        }
        $client->KundGrunduppgifter(Customer);

    ?>
</body>
</html>

my php code so far (Dont laugh! xD)

Member Avatar for LastMitch

@Dendei

the database part is no problem i just need help sending the text from textboxes-->class-->thru Wcf -->c# program

I be honest with you. It's very confusing! You have codes from C# and you want to add
php with it? I don't know how to read C#. I don't think anyone can help you with this one. Try to ask someone in Software Development section and ask some suggestion. Then come back with what you have and if it makes sense then someone can help you but for now, its' bit a challenge for anyone.

but dont mind the C# code so much, all you need to know about it is that i pass a method from it to WCF service.
Then i call the method in my php code

a method containing variables you should put in, preferably also with a class
but what i dont know is how to code php well.
i dont know if i can just make a class and pass it in a method in php? or how it works?

when i do my test with WCF test client everything works fine so it must be something with my php code

$CustomerNumber = textbox1.text this is what does not work. I suggest you try with test values first, like this: public $CustomerNumber = '1001';

If you want output, change line 17 to:

echo $client->KundGrunduppgifter(Customer);

When you get that to work, we'll discuss how you can get it from an input.

html>
<head>
<title>My First PHP Page</title>
</head>
<body>
    <?php

        $client = new SoapClient("http://localhost:8731/phpwcf/?wsdl");

        class Kund
        {
            $KundNummer = "666";
            $KundNamn = "Iron Maiden";
            //$Telefon = "Number of the best!";
            //$PostAdr = "Bottom of the Hell";
        }
        $client->KundGrunduppgifter(Kund);

    ?>
</body>
</html>

my code is like this atm but dont i have to, like access my DataContract and then write to that? doesent seem to work to just give the method a class

i get this error in my webbrowser

Fatal error: Uncaught SoapFault exception: [a:DeserializationFailed] The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'KundGrunduppgifter'. End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 159. in C:\wamp\www\test\test.php:17 Stack trace: #0 C:\wamp\www\test\test.php(17): SoapClient->__call('KundGrunduppgif...', Array) #1 C:\wamp\www\test\test.php(17): SoapClient->KundGrunduppgifter('666', 'Iron Maiden') #2 {main} thrown in C:\wamp\www\test\test.php on line 17

Does this return anything?

var_dump($client->__getFunctions());

What you can try to send as data is something like this:

$Kund = array (
    'KundNummer' => '666',
    'KundNamn' => 'Iron Maiden'
);

Oh crap, just noticed this. You are trying to send a class, you need to send an object.

$KundObj = new Kund();
echo $client->KundGrunduppgifter($KundObj);

Dont think so i put echo var_dump($client->__getFunctions()); and didnt get anything
*

$KundObj = new Kund();
echo $client->KundGrunduppgifter($KundObj);

worked better :)
but still get this error
Parse error: syntax error, unexpected '$KundNummer' (T_VARIABLE), expecting function (T_FUNCTION) in C:\wamp\www\test\test.php on line 12

*
*
*
my code so far

<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
    <?php

        $client = new SoapClient("http://localhost:8731/phpwcf/?wsdl");
        echo var_dump($client->__getFunctions());
        class Kund
        {
            $KundNummer = "666";
            $KundNamn = "Iron Maiden";
            //$Telefon = "Number of the best!";
            //$PostAdr = "Bottom of the Hell";
        }
        $KundObj = new Kund();
        $client->KundGrunduppgifter($KundObj);

    ?>
</body>
</html>

its strange because it works when i test the method with WCF Test Client

Try this, it's a more complete class:

<html>
<head>
<title>My First PHP Page</title>
</head>
<body>
    <?php
        class Kund
        {
            public $KundNummer;
            public $KundNamn;

            function __construct($nummer, $namn)
            {
                $this->KundNummer = $nummer;
                $this->KundNamn = $namn;
            }
        }

        $client = new SoapClient("http://localhost:8731/phpwcf/?wsdl");
        var_dump($client->__getFunctions());

        $KundObj = new Kund('666', 'Iron Maiden');
        var_dump($client->KundGrunduppgifter($KundObj));
    ?>
</body>
</html>

error/output

array (size=1)
  0 => string 'KundGrunduppgifterResponse KundGrunduppgifter(KundGrunduppgifter $parameters)' (length=77)

( ! ) Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\test\test.php on line 20
Call Stack
#   Time    Memory  Function    Location
1   0.0008  142872  {main}( )   ..\test.php:0

*
*
*
C# error

{"Object reference not set to an instance of an object."}
nullReferenceExeption

*
*
seems like i dont get the variables thru?
wcf test client still works but hmmm
how can it be null? can i test so i see the $KundObj gets the variables?

Been a while for me. You can var_dump($KundObj);

I think the parameter list needs to be changed:

$KundObj = new Kund('666', 'Iron Maiden');
$params = array (
    'Kund' => $KundObj
);

var_dump($client->KundGrunduppgifter($params));
//or
var_dump($client->__soapCall('KundGrunduppgifter', $params));

As it is mentioned in the manual.

commented: Wow, you just pull a rabbit out of the hat! +5

Ok it works ^^ thank you Pritaeas - Posting Genius and very good link worked with my return value aswell good job and thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.