-
January 16th, 2012, 11:51 AM
#1
Web service...need to write text string directly to network shared printer
I have a web service that is currently calling the DOS command copy to put a text file to a specified network share. This is the code:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data
Imports System.IO
Imports System.Xml
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class ZebraPrinter
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function PrintCaseLabels(ByVal input1 As informationtopass) As returnparams
Dim adapter As New System.Data.SqlClient.SqlDataAdapter
Dim ds As New System.Data.DataSet
Dim stringxml As String
Dim rp As New returnparams
'Dim sql As String
Dim cn As New System.Data.SqlClient.SqlConnection
cn.ConnectionString = "database=ee8idbbd;server=jomar;uid=reports;pwd=reports;Max Pool Size=300"
cn.Open()
Dim cmd As New System.Data.SqlClient.SqlCommand
Try
cmd.Connection = cn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "bdg_proccaselabelstoprint"
cmd.Parameters.AddWithValue("@STYLE", input1.STYLE.ToString)
cmd.Parameters.AddWithValue("@COLORCODE", input1.color.ToString)
cmd.Parameters.AddWithValue("@SIZECODE", input1.size.ToString)
cmd.Parameters.AddWithValue("@CASEQUANTITY", input1.quantity)
cmd.Parameters.AddWithValue("@COUNTRY", input1.country.ToString)
adapter.SelectCommand = cmd
adapter.Fill(ds)
stringxml = ds.Tables(0).Rows(0).Item(0)
Using writer As New System.IO.StreamWriter(Server.MapPath("/") & "Newoutput.xml")
writer.Write(stringxml)
End Using
Dim transformer As New System.Xml.Xsl.XslCompiledTransform
Dim document As New XmlDocument
document.Load(Server.MapPath("/") & "Newoutput.xml")
rp.casenumber = 0
Dim navigator As XPath.XPathNavigator = document.CreateNavigator
Dim list = document.GetElementsByTagName("casenumber")
For Each item As System.Xml.XmlElement In list
rp.casenumber = item.InnerText
Next
transformer.Load(Server.MapPath("/") & "XSLTFile1.xslt")
Dim output As New StringWriter
transformer.Transform(navigator, Nothing, output)
Dim newstream As New FileStream(Server.MapPath("/") & "NewOutput.txt", FileMode.Create)
Dim newwriter As New StreamWriter(newstream)
newwriter.Write(output.ToString)
newwriter.Close()
output.Close()
Process.Start("cmd.exe", "/c type " & Server.MapPath("/") & "NewOutput.txt >" & input1.networkshare.ToString)
Catch ex As Exception
Dim exceptionstream As New FileStream(Server.MapPath("/") & "error.txt", FileMode.Create)
Dim excwriter As New StreamWriter(exceptionstream)
excwriter.Write(ex.ToString)
excwriter.Close()
Finally
cn.Close()
cn = Nothing
End Try
Return rp
End Function
End Class
Public Class InformationToPass
Public STYLE As String
Public color As String
Public size As String
Public quantity As Long
Public country As String
Public networkshare As String
End Class
Public Class returnparams
Public casenumber As String
End Class
It appears doing this might be causing some problems and our front-end programmer suggested I see if I can output the stream "output" directly to the network shared printer specified by the SOAP request.
Is this possible? This is VS 2010
-
January 16th, 2012, 01:41 PM
#2
Re: Web service...need to write text string directly to network shared printer
You want the network to trust the Web Service? That's all about shared trust situations.
-
January 16th, 2012, 01:46 PM
#3
Re: Web service...need to write text string directly to network shared printer
Well, yes, actually I do. It's an Intranet site.
-
January 16th, 2012, 06:28 PM
#4
Re: Web service...need to write text string directly to network shared printer
Well, if you are using the Azure Cloud system, you can do that. Getting an ISP might be harder.
-
January 17th, 2012, 08:34 AM
#5
Re: Web service...need to write text string directly to network shared printer
It's an inTRAnet site. All on this side of the firewall
-
January 20th, 2012, 09:38 AM
#6
Re: Web service...need to write text string directly to network shared printer
-
January 20th, 2012, 11:39 AM
#7
Re: Web service...need to write text string directly to network shared printer
Call them. I don't use them, or work there. Sorry.
-
January 20th, 2012, 04:33 PM
#8
Re: Web service...need to write text string directly to network shared printer
Call who? This has nothing to do with an ISP or the internet. This is one machine on the network, talking to another machine on the same network.
-
January 20th, 2012, 06:58 PM
#9
Re: Web service...need to write text string directly to network shared printer
I have not used SOAP or AJAX so I do not know what features may be there. I do know that you should use code tags when posting code so as to make it readable.
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|