0

コンソールアプリでうまく機能する機能があります。しかし、それをWCFに移動すると、毎回爆撃されます。私が間違っていることを理解することはできません。

運用契約は次のとおりです。

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

これがsvcです:

インポートSystem.CollectionsインポートシステムインポートSystem.DataインポートSystem.Data.SqlClientインポート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

そして最後に、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))

私はそれを理解することはできません。誰かアイデアはありますか?WCFはストリームライターをサポートしていませんか?どんなアイデアでも大歓迎です!

ありがとう、ジェイソン

4

1 に答える 1

1

コンソールから実行したときにコードが機能する場合は、svcとして実行したときのコンテキストに関係していると思います。IIS経由でsvcを実行していますか?どのアカウント?そのアカウントには、ファイルを作成しようとしているパスへの書き込みアクセス権がありますか?

于 2011-04-28T20:38:18.300 に答える