Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why I can't use System.Drawing in Web Service project ?

Status
Not open for further replies.

majkinetor

Programmer
Feb 21, 2006
88
RS
anybody ?

So, can anybody tell me is there any theory behind this fact that sam namespaces are visible from some projects while not from others ?
 
I am assuming because a web service is not visual, it just returns something, strings, objects etc. Since it is not visual, how would you use System.Drawing. Just as there is no response or request ojbect available.

Jim
 
I assumed that also, but I found this code in ASP Unleashed book (1.1 framework)

This is the part from this book:

Web Services and Binary Files
You can pass and retrieve binary files to and from a Web service. For example, you could create a Web service that works with music files, program files, or images.

The Web service in Listing 22.13 generates an image from a string of text.
Code:
Listing 22.13 ImageService.asmx
<%@ WebService Class="ImageService" %>

Imports System
Imports System.Web.Services
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO

<WebService( Namespace:="[URL unfurl="true"]http://yourdomain.com/webservices"[/URL] )> _
Public Class ImageService : Inherits WebService

<WebMethod()> Public Function GetTextImage( strText As String ) As Byte()
  Dim objBitmap As Bitmap
  Dim objGraphics As Graphics
  Dim objFont As Font
  Dim strmBuffer As MemoryStream

  objBitmap = New Bitmap( 300, 50 )
  objGraphics = Graphics.FromImage( objBitmap )
  objFont = New Font( "Impact", 24 )
  objGraphics.DrawString( strText, objFont, Brushes.Red, 1, 1 )

  strmBuffer = New MemoryStream()
  objBitmap.Save( strmBuffer, ImageFormat.Gif )
  Return strmBuffer.ToArray()
End Function

End Class
The C# version of this code can be found on the CD-ROM.

The Web service in Listing 22.13 contains a method named GetTextImage. When you pass a string of text to this method, it generates an image that displays the text.

The image is represented by a bitmap. You cannot return a bitmap directly from a method in a Web service. In Listing 22.13, the bitmap is first converted into a byte array by using the ToArray method of the MemoryStream class. The Web method returns the byte array.
 
But I can't compile this example (I tried VB & CS).
What is the catch ?

Some compiler flag ?
 
But I can't compile this example
Do you get an error? There is no reason why you shouldn't be able to use the drawing class (although, as the example states, returning the results has to be done differently).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Ok... I solved the problem

I needed to add manualy reference via "Add reference" command, which I don't have to do for other projects ....

thats it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top