Agregar al inicio de cualquier fichero js, la ´línea del fichero de referencia como puede ser el fichero de jQuery.
Ejemplo:
/// <reference path="../jQuery/jquery-2.1.0.js" />
/// <reference path="../jQuery/jquery.validate.js" />
1 + 1 = 10
Blog de programación del mundo .NET de David Martínez Fresneda
domingo, 11 de mayo de 2014
Ejemplo de entrada en el web.config de configuración de log4net
<configuration>
...
<log4net>
<root>
<level
value="ALL"
/>
<appender-ref
ref="LogFileAppender"
/>
</root>
<appender
name="LogFileAppender"
type="log4net.Appender.RollingFileAppender,log4net">
<param
name="File"
value="C:\Log\SampleLog.txt"
/>
<param
name="AppendToFile"
value="true"
/>
<rollingStyle
value="Size"
/>
<maxSizeRollBackups
value="2"
/>
<maximumFileSize
value="100KB"
/>
<staticLogFileName
value="true"
/>
<datePattern
value="yyyyMMdd"
/>
<layout
type="log4net.Layout.PatternLayout">
<conversionPattern
value="%date
[%thread] %-5level %logger - %message%newline"
/>
</layout>
</appender>
</log4net>
</configuration>
Llamada jquery ajax de ejemplo
Código cliente:
Código servidor:
$.ajax({
url: "Webform1.aspx/MetodoPublico",
success: RespuestaMetodo,
error: function Error(msg) {
alert('Hubo un error.');
},
data: "{ nombre: Pepe'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "POST"
})
Función CallBack:
function RespuestaMetodo(data) { //Recupero la nueva lista de becas var texto = data.d;
}
Código servidor:
[WebMethod]
public static string MetodoPublico(string nombre) {
return "Hola: " + nombre;
}
lunes, 14 de octubre de 2013
AcceptAllCertifications method to access https
public static bool AcceptAllCertifications (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { return true; }
martes, 1 de octubre de 2013
Hacer una llamada por REST del tipo GET desde .NET (Cogido de otro post)
void CallGetMethod()
{
// Restful service URL
string url = "http://localhost/wcdir/service.svc/GetSampleMethod/str/method1";
string strResult = string.Empty;
// declare httpwebrequet wrt url defined above
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
// set method as post
webrequest.Method = "GET";
// set content type
webrequest.ContentType = "application/json";
// declare & read response from service
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
// set utf8 encoding
Encoding enc = System.Text.Encoding.GetEncoding("utf-8");
// read response stream from response object
StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc);
// read string from stream data
strResult = loResponseStream.ReadToEnd();
// close the stream object
loResponseStream.Close();
// close the response object
webresponse.Close();
// assign the final result to text box
txtResult.Text = strResult;
}
{
// Restful service URL
string url = "http://localhost/wcdir/service.svc/GetSampleMethod/str/method1";
string strResult = string.Empty;
// declare httpwebrequet wrt url defined above
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
// set method as post
webrequest.Method = "GET";
// set content type
webrequest.ContentType = "application/json";
// declare & read response from service
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
// set utf8 encoding
Encoding enc = System.Text.Encoding.GetEncoding("utf-8");
// read response stream from response object
StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc);
// read string from stream data
strResult = loResponseStream.ReadToEnd();
// close the stream object
loResponseStream.Close();
// close the response object
webresponse.Close();
// assign the final result to text box
txtResult.Text = strResult;
}
Hacer una llamada por REST del tipo POST desde .NET
public static void CallPostMethod() { //Para el https ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); // Restful service URL string url = https://ipv4.fiddler/servicio.svc/metodo; // declare ascii encoding ASCIIEncoding encoding = new ASCIIEncoding(); string strResult = string.Empty; // sample xml sent to Service & this data is sent in POST string SampleXml = @"{ ""strOf"":""strOf"", ""strTran"":""strTran"", ""strTipoC"":""strTipoC"", ""strNumC"":""strNumC"", ""dtmFecha"" : ""\/Date(1255131630400)\/"" }"; string postData = SampleXml.ToString(); // convert xmlstring to byte using ascii encoding byte[] data = encoding.GetBytes(postData); // declare httpwebrequet wrt url defined above HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url); // set method as post webrequest.Method = "POST"; // set content type webrequest.ContentType = "application/json"; // set content length webrequest.ContentLength = data.Length; // get stream data out of webrequest object Stream newStream = webrequest.GetRequestStream(); newStream.Write(data, 0, data.Length); newStream.Close(); // declare & read response from service HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse(); // set utf8 encoding Encoding enc = System.Text.Encoding.GetEncoding("utf-8"); // read response stream from response object StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc); // read string from stream data strResult = loResponseStream.ReadToEnd(); // close the stream object loResponseStream.Close(); // close the response object webresponse.Close(); }
Suscribirse a:
Entradas (Atom)