WFC Soap class within an class communicating with PHP

Within the Windows Foundation Classes you are able to create SOAP end points. These end points you are able to communicate using classes funny enough (because of the WFC being classes). But to communicate with these is fine with PHP and also when you sometimes have a class within an class as a parameter passing to the SOAP end point. Well you are able to do it within PHP as well.

If you have a WFC service and add these to the service for the ServiceContract and create the DataContract’s and DataMembers

[ServiceContract]
public interface IService1
{
    [OperationContract]
    string NewValue(NewName name);
}
 
[DataContract]
public class SecondName
{
    int svalue1;
    int svalue2;
 
    [DataMember]
    public int Svalue1
    {
        get { return svalue1; }
        set { svalue1 = value; }
    }
 
    [DataMember]
    public int Svalue2
    {
        get { return svalue2; }
        set { svalue2 = value; }
    }
}
 
[DataContract]
public class NewName
{
    SecondName secondValue = new SecondName();
 
    [DataMember]
    public SecondName SecondValue
    {
        get { return secondValue; }
        set { secondValue = value; }
    }
}

Created the SecondName class as the second named class with the svalue1/2 within in turn the NewName named class will reference the SecondName class.

And then within the class that implements the interface here is the function name to call within the soap end point called NewValue.

public string NewValue(NewName namesec)
{
    return string.Format("Value : {0}", namesec.SecondValue.Svalue1 + namesec.SecondValue.Svalue2);
}

Well to find out what you need to pass to the soap call I was using an WFC application to write out the debugging information with altering the web.config by

    <system.serviceModel>
      <diagnostics>
        <messageLogging
             logEntireMessage="true"
             logMalformedMessages="false"
             logMessagesAtServiceLevel="true"
             logMessagesAtTransportLevel="false"
             maxMessagesToLog="3000"
             maxSizeOfMessageToLog="2000"/>
      </diagnostics>
    </system.serviceModel>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="messages"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData="c:\temp\messages.svclog" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

which in turns creates a file and in that file there is xml definition what is being sent.

<s:Body>
 <NewValue xmlns="http://tempuri.org/">
 <name xmlns:d4p1="http://schemas.datacontract.org/2004/07/WcfService1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
 <d4p1:SecondValue><d4p1:Svalue1>200</d4p1:Svalue1><d4p1:Svalue2>100</d4p1:Svalue2></d4p1:SecondValue>
 </name>
 </NewValue></s:Body>
</xml>

and within PHP you are able to copy this. but note that the parameter to send is “name” which is not the same as the parameter above (namesec) you have to send to “name” which is what the soap end point is looking for.

class SecondName {
    public $Svalue1;
    public $Svalue2;
}
 
class NewName {
    public $SecondValue;
 
    public function NewName($s1, $s2)
    {
        $this->SecondValue = new SecondName();
        $this->SecondValue->Svalue1 = $s1;
        $this->SecondValue->Svalue2 = $s2;
    }
}
 
$objN = new NewName(200,100);
 
//Create a SOAP client
$client = new SoapClient("http://192.168.0.3/Service1.svc?wsdl");
$retVal = $client->NewValue(array ("name" => $objN));
 
print_r($retVal->NewValueResult);

and the output is

Value : 300

Have attached a file of the project for the WFC webserver and also the php code.