lunes, 19 de noviembre de 2007

Creación de WebServices IIS + VS205

Código en vs2005.

using System;

using System.Collections;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace webService {

[WebService(Namespace = "http://tempuri.org/Pruebas", Description = "Prueba servicio Web.")]
public class Class1 : System.Web.Services.WebService {
public string HelloWorld() {
return "Hello World";
}

[WebMethod(CacheDuration = 30, Description = "Devuelve una prueba")]
public string GetPrueba() {
return "Esto es una prueba";
}
}



Una vez creada esta dll hay que añadirla al IIS como nueva aplicación.

Para probar el servicio se utilizará el código:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Services.Description;

namespace probeWebService {
public partial class Form1 : Form {
public delegate void pruebaDlg(object data);

public pruebaDlg delegado;

public Form1() {
InitializeComponent();
this.delegado = new pruebaDlg(pruebas);
}

[SoapDocumentMethodAttribute("http://tempuri.org/pruebas/Service.asmx/GetPrueba", Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public string getPruebas(string data) {
object results = this.Invoke(delegado, data);
return ((string)(results));
}

public void pruebas(object data) {
Console.WriteLine(data.ToString());
}
private void button1_Click(object sender, EventArgs e) {
getPruebas("probando...");
}
}
}

1 comentario:

  1. Anónimo8:33 p. m.

    Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Wireless, I hope you enjoy. The address is http://wireless-brasil.blogspot.com. A hug.

    ResponderEliminar