Archive for the ‘WCF Service’ Category

Send Json Data to Webservice and get response from Webservice

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Text;
using System.IO;
using System.Data;
using System.Web.Script.Serialization;

 

string url =”http://abc.com”;

var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = “application/json”;
httpWebRequest.Method = “POST”;

using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = new JavaScriptSerializer().Serialize(new
{
empid = “1001”,
empname = “test name”,
empsalary= “10000”
});

streamWriter.Write(json);
}

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}

WCF Service Url using the computer name instead of the IP address and PC Name can not be resolved

In Web.config file add below code in <system.serviceModel>
< serviceHostingEnvironment multipleSiteBindingsEnabled=”true” />
< / system.serviceModel >

Return data from datatable into xml format

We can return data stored in datatable into xml format by below ways.

1) As XmlDocument

Make datatable values in to xml string format and then convert it into xml document element.

strxml = “<?xml version=’1.0′ encoding=’utf-8′ ?>” +
“<DATA>” +
“<EMPNO>” + DT.ROWS[0][“EMPNO”] + “</EMPNO>” +

“<EMPNAME>” + DT.ROWS[0][“EMPNAME”] + “</EMPNAME>” +

“</DATA>”;

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strxml);
return xmlDoc.DocumentElement;

2) As XML String

Make datatable values in to xml string format and then convert it into xml document element.

strxml = “<?xml version=’1.0′ encoding=’utf-8′ ?>” +
“<DATA>” +
“<EMPNO>” + DT.ROWS[0][“EMPNO”] + “</EMPNO>” +

“<EMPNAME>” + DT.ROWS[0][“EMPNAME”] + “</EMPNAME>” +

“</DATA>”;

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strxml);
return xmlDoc.OuterXml;

Error : System.Data.OracleClient requires Oracle client software version 8.1.7 or greater during hosting wcf service on windows server 2012

Error :

System.Data.OracleClient requires Oracle client software version 8.1.7 or greater

 

Solution :

If other applications with database interaction on windows server 2012 are working property, then remove new hosted wcf service. Create new virtual directory for hosting wcf service. Assign Application Pool to virtual directory. Then Stop IIS and restart IIS. Now check your wcf service at client side or in client application. It will work without producing oracle error.

Apply full rights to virtual directory folder. Add Network Services & IIS_Iusers with full rights.