2011-04-28 11 views
0

私のコンソールアプリケーションでうまく動作する機能があります。しかし、私がWCFに移動すると、毎回それが爆発します。私が間違っていることを理解できません。ここでWCFからStreamWriterを呼び出す

は動作契約です:

<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はストリームライターをサポートしていませんか?どんなアイデアも大歓迎です!あなたは、コンソールから実行時にコードが動作する場合

おかげで、 ジェイソン

+0

例外の詳細は役に立ちます... –

答えて

1

は、私はそれはSVCとして実行されたとき、それはコンテキストに関係していることを推測します。 IIS経由であなたのsvcを実行していますか?どのアカウントですか?そのアカウントは、ファイルを作成しようとしているパスへの書き込みアクセス権を持っていますか?

+0

セキュリティは問題でした - 100万に感謝! –

+0

クール..まあ、私はちょっと新しいので、正しい答えとして私のポストをマークする必要がありますか? – Joakim

関連する問題