Here I am going to Explain How Can you show Random Image Using WCF ?
In previous articles I explained How can you Create WCF application .
Download Code Here
Demo :
In previous articles I explained How can you Create WCF application .
Download Code Here
Demo :
Create WCF Service and Give the WCF service Name Mywcfapp.svc.
It Display 2 Section IMywcfapp.cs and Mywcfapp.cs.
Step 1:
Go to IMywcfapp.cs and Write the below code.
NameSpace :
using System.Web.UI.WebControls;
[ServiceContract]
public interface IMywcfapp
{
[OperationContract]
void DoWork();
void displayimage(Image img);
}
Step 2:
Go to Mywcfapp.cs and Write the below code.
public class Mywcfapp: IMywcfapp
{
public void DoWork()
{
}
public void displayimage(System.Web.UI.WebControls.Image img)
{
Random rr = new Random();
switch (rr.Next(5))
{
case 0: img.ImageUrl = "Desert.jpg"; //image URL
break;
case 1: img.ImageUrl = "Chrysanthemum.jpg"; //image URL
break;
case 2: img.ImageUrl = "Hydrangeas.jpg"; //image URL
break;
case 3: img.ImageUrl = "Jellyfish.jpg"; //image URL
break;
default: img.ImageUrl = "Tulips.jpg"; //image URL
break;
throw new NotImplementedException();
}
}
}
Step 3: Add Images in Application folder.
Step 4: Create .aspx page and copy and paste the below code,
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Random Image</title>
</head>
<body>
<form id="form1" runat="server">
<table class="style1">
<tr>
<td>
</td>
<td>
<asp:Image ID="Image1" runat="server" Height="180px" Width="206px" />
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="NEXT" />
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
<div>
</div>
</form>
</body>
</html>
Step 4: Then Go to the .aspx.cs page and write the below code,
Service obj = new Service();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
obj.displayimage(Image1);
}
Now run the program.
If this Post helps you, then please share.
No comments:
Post a Comment