Archive for July, 2015

Check Transaction amount having decimal point or not

Using Below code, we can trace entered amount has decimal point or not.

AMOUNT = 500.25;

AMOUNT.ToString().IndexOf(“.”) != -1

AMOUNT.ToString().IndexOf(“.”) returns -1 if amount has no decimal point

AMOUNT.ToString().IndexOf(“.”) returns >0 value if amout has decimal point.

 

Enable Cross-domain Ajax requests using web.config

Error : 

XMLHttpRequest cannot load webservice.asmx. No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

Solution : 

Add Below code in web.config file.

<system.webServer>

<httpProtocol>

<customHeaders>
<!–Allow Web API to be called from a different domain.–>

<add name=”Access-Control-Allow-Origin” value=”*” />

</customHeaders>

</httpProtocol>

</system.webServer>

Enable ASP.NET ASMX web service for HTTP POST / GET requests

Add below code in web.config file.

<system.web>

<webServices>

<protocols>

<add name=”HttpGet” />
<add name=”HttpPost” />

</protocols>

</webServices>

</system.web>

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.