Web service...need to write text string directly to network shared printer
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Web service...need to write text string directly to network shared printer

  1. #1
    Join Date
    Jan 2012
    Posts
    10

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,981

    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.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jan 2012
    Posts
    10

    Re: Web service...need to write text string directly to network shared printer

    Well, yes, actually I do. It's an Intranet site.

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,981

    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.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jan 2012
    Posts
    10

    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

  6. #6
    Join Date
    Jan 2012
    Posts
    10

    Re: Web service...need to write text string directly to network shared printer

    Anyone???

  7. #7
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,981

    Re: Web service...need to write text string directly to network shared printer

    Call them. I don't use them, or work there. Sorry.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Jan 2012
    Posts
    10

    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.

  9. #9
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,823

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center