开发者

Calling StreamWriter from WCF

开发者 https://www.devze.com 2023-03-01 15:29 出处:网络
I have a function which works great in my console app. But when I move it over to my WCF, it bombs out every time. Can\'t figure out what I\'m doing wrong.

I have a function which works great in my console app. But when I move it over to my WCF, it bombs out every time. Can't figure out what I'm doing wrong.

开发者_开发知识库Here's the operation contract:

<OperationContract()> _
Function SendLetterToBatch(ByVal FinishedLetter As Letter) As Boolean
'Sends a completed letter to the batch for XStream, returns true/false.

Here's the svc:

Imports System.Collections Imports System Imports System.Data Imports System.Data.SqlClient Imports System.IO

Public Function SendLetterToBatch(ByVal FinishedLetter As Letter) As Boolean Implements ILetterWriter.SendLetterToBatch
    Dim CurDateTime As DateTime = DateTime.Now
    Dim Format As String = "yyyyMMdd HHmmss"
    Dim FileName As String


    'Create the text file name. Date / Time (yyyyMMdd HHmmss) to precede claim / policy number
    FileName = CurDateTime.ToString(Format) & FinishedLetter.ClaimOrPolicyNo.ToString


    'Remove Me -- temporary text file location
    FileName = "D:\" & FileName.ToString & ".txt"


    'Write the letter to the text file
    Using writer As StreamWriter = New StreamWriter(FileName)
        writer.Write("01")
        writer.Write("02" & FinishedLetter.Body.ToString)
        writer.Write("03")
    End Using


    'Function completed fine, return true
    SendLetterToBatch = True

End Function

And finally, the console app calling the WCF:

    Dim objLetter As New Letter

    objLetter._ClaimOrPolicyNo = 99999
    objLetter._CompID = 23
    objLetter._StateID = 12
    objLetter._Body = "Dear Sir, you have not had much luck winning the lottery. We hope we can help. Next time, please choose 6/7/8/9/1 BONUS 2 on your ticket. Thank you, Us."

    Console.Write(client.SendLetterToBatch(objLetter))

I can't figure it out. Anybody have any ideas? Does WCF not support streamwriter? Any ideas would be greatly appreciated!

Thanks, Jason


If the code works when you run it from console, I would guess that it has to do with the context when it is executed as a svc. Are you running your svc via IIS? which account? does that account has write-access to the path where you are trying to create a file?

0

精彩评论

暂无评论...
验证码 换一张
取 消