{"id":1783,"date":"2012-08-04T22:00:20","date_gmt":"2012-08-04T21:00:20","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=1783"},"modified":"2012-08-04T22:05:00","modified_gmt":"2012-08-04T21:05:00","slug":"wfc-soap-class-within-an-class-communicating-with-php","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2012\/08\/04\/wfc-soap-class-within-an-class-communicating-with-php\/","title":{"rendered":"WFC Soap class within an class communicating with PHP"},"content":{"rendered":"<p><span id=\"zipfile\"><a href='http:\/\/www.codingfriends.com\/wp-content\/uploads\/2012\/08\/WFC.SOAP_PHP.zip'><\/a><\/span>Within the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Microsoft_Foundation_Class_Library\" title=\"Windows Foundation Class\" target=\"_blank\">Windows Foundation Classes<\/a> 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.<\/p>\n<p>If you have a WFC service and add these to the service for the ServiceContract and create the DataContract&#8217;s and DataMembers<\/p>\n<pre lang=\"csharp\">\r\n[ServiceContract]\r\npublic interface IService1\r\n{\r\n    [OperationContract]\r\n    string NewValue(NewName name);\r\n}\r\n\r\n[DataContract]\r\npublic class SecondName\r\n{\r\n    int svalue1;\r\n    int svalue2;\r\n\r\n    [DataMember]\r\n    public int Svalue1\r\n    {\r\n        get { return svalue1; }\r\n        set { svalue1 = value; }\r\n    }\r\n\r\n    [DataMember]\r\n    public int Svalue2\r\n    {\r\n        get { return svalue2; }\r\n        set { svalue2 = value; }\r\n    }\r\n}\r\n\r\n[DataContract]\r\npublic class NewName\r\n{\r\n    SecondName secondValue = new SecondName();\r\n\r\n    [DataMember]\r\n    public SecondName SecondValue\r\n    {\r\n        get { return secondValue; }\r\n        set { secondValue = value; }\r\n    }\r\n}\r\n<\/pre>\n<p>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.<\/p>\n<p>And then within the class that implements the interface here is the function name to call within the soap end point called NewValue.<\/p>\n<pre lang=\"csharp\">\r\npublic string NewValue(NewName namesec)\r\n{\r\n    return string.Format(\"Value : {0}\", namesec.SecondValue.Svalue1 + namesec.SecondValue.Svalue2);\r\n}\r\n<\/pre>\n<p>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<\/p>\n<pre lang=\"xml\">\r\n    <system.serviceModel>\r\n      <diagnostics>\r\n        <messageLogging\r\n             logEntireMessage=\"true\"\r\n             logMalformedMessages=\"false\"\r\n             logMessagesAtServiceLevel=\"true\"\r\n             logMessagesAtTransportLevel=\"false\"\r\n             maxMessagesToLog=\"3000\"\r\n             maxSizeOfMessageToLog=\"2000\"\/>\r\n      <\/diagnostics>\r\n    <\/system.serviceModel>\r\n  <system.diagnostics>\r\n    <sources>\r\n      <source name=\"System.ServiceModel.MessageLogging\">\r\n        <listeners>\r\n          <add name=\"messages\"\r\n          type=\"System.Diagnostics.XmlWriterTraceListener\"\r\n          initializeData=\"c:\\temp\\messages.svclog\" \/>\r\n        <\/listeners>\r\n      <\/source>\r\n    <\/sources>\r\n  <\/system.diagnostics>\r\n<\/pre>\n<p>which in turns creates a file and in that file there is xml definition what is being sent.<\/p>\n<pre lang=\"xml\">\r\n<s:Body>\r\n <NewValue xmlns=\"http:\/\/tempuri.org\/\">\r\n <name xmlns:d4p1=\"http:\/\/schemas.datacontract.org\/2004\/07\/WcfService1\" xmlns:i=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\">\r\n <d4p1:SecondValue><d4p1:Svalue1>200<\/d4p1:Svalue1><d4p1:Svalue2>100<\/d4p1:Svalue2><\/d4p1:SecondValue>\r\n <\/name>\r\n <\/NewValue><\/s:Body>\r\n<\/xml>\r\n<\/pre>\n<p>and within PHP you are able to copy this. but note that the parameter to send is &#8220;name&#8221; which is not the same as the parameter above (namesec) you have to send to &#8220;name&#8221; which is what the soap end point is looking for.<\/p>\n<pre lang=\"php\">\r\nclass SecondName {\r\n    public $Svalue1;\r\n    public $Svalue2;\r\n}\r\n\r\nclass NewName {\r\n    public $SecondValue;\r\n    \r\n    public function NewName($s1, $s2)\r\n    {\r\n        $this->SecondValue = new SecondName();\r\n        $this->SecondValue->Svalue1 = $s1;\r\n        $this->SecondValue->Svalue2 = $s2;\r\n    }\r\n}\r\n\r\n$objN = new NewName(200,100);\r\n\r\n\/\/Create a SOAP client\r\n$client = new SoapClient(\"http:\/\/192.168.0.3\/Service1.svc?wsdl\");\r\n$retVal = $client->NewValue(array (\"name\" => $objN));\r\n\r\nprint_r($retVal->NewValueResult);\r\n<\/pre>\n<p>and the output is<\/p>\n<pre lang=\"bash\">\r\nValue : 300\r\n<\/pre>\n<p>Have attached a file of the project for the WFC webserver and also the php code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2012\/08\/04\/wfc-soap-class-within-an-class-communicating-with-php\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">WFC Soap class within an class communicating with PHP<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,17],"tags":[47,175,392],"class_list":["post-1783","post","type-post","status-publish","format-standard","hentry","category-c_sharp","category-php","tag-class","tag-soap","tag-wfc"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1783","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=1783"}],"version-history":[{"count":5,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1783\/revisions"}],"predecessor-version":[{"id":1789,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1783\/revisions\/1789"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=1783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=1783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=1783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}