Wednesday, January 14, 2015

Consume wcf service with wsHttpBinding using PHP Soap Client

Recently I wrote blog post on accessing wcf using php. But that was with basicHttpBinding. Somehow after long research I found how to consume wcf with wsHttpBinding. Follow the codes,




using System;
using System.Linq;
using System.ServiceModel;
namespace WcfServiceLibrary1
{
[ServiceContract(Namespace = "http://tempuri.org")]
public interface IService1
{
[OperationContract]
string GetData(int value);
}
}
view raw IService1.cs hosted with ❤ by GitHub

using System;
using System.Linq;
using System.ServiceModel;
namespace WcfServiceLibrary1
{
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
}
view raw Service1.cs hosted with ❤ by GitHub

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8733/test/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1" contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" openTimeout="00:10:00"
closeTimeout="00:10:00"
receiveTimeout="00:10:00"
sendTimeout="00:10:00"
maxReceivedMessageSize="2147483647"
maxBufferPoolSize="2147483647">
<security mode="None" />
<reliableSession enabled="false" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" httpGetUrl="http://localhost:8733/test/WcfServiceLibrary1/Service1/"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
view raw App.config hosted with ❤ by GitHub

<?php
try {
$params = array("soap_version"=> SOAP_1_2,
"trace"=>1,
"exceptions"=>0,
);
$client = new SoapClient('http://localhost:8733/test/WcfServiceLibrary1/Service1/?wsdl',$params);
$actionHeader = new SoapHeader('http://www.w3.org/2005/08/addressing','Action','http://tempuri.org/IService1/GetData',true);
$client->__setSoapHeaders($actionHeader);
$params = new StdClass;
$params->value = 2;
$retval = $client->GetData($params);
if (is_soap_fault($retval)) {
trigger_error("SOAP Fault: (faultcode: {$retval->faultcode}, faultstring: {$retval->faultstring})", E_USER_ERROR);
}
else{
echo $retval->GetDataResult;
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>
view raw wcf.php hosted with ❤ by GitHub

Tuesday, January 13, 2015

How to move WordPress from local server to live site

Many of us develop wordpress sites using local server in order to speed up the development process. Issue comes with moving website to live host. Even we configured MySql and wp-config.php files correctly we can see some broken links. Here I list down steps you need to host in a live environment.

Step 1 : Configure the Mysql


Log in to cpanel and create a database, add user and assign user to database





Step 2 : Change the wp-config.php file



Step 3 : Upload sql and files to live host


You can upload website files using ftp client or directly using cpanel file manager.

Upload sql


You need to log to phpmyadmin (localhost/phpmyadmin) in your local server and export database to .sql file



Open .sql using text editor and change the following changes according to your database name



Open your live phpmyadmin and import the .sql file



Step 4: Fix links


Run below sql queries according to your domain names




Everything should work now. Happy Wordpressing :)