2011-12-08 11 views
2

EDIT:私の呼び出しスタックです。WCFサービスで作業しようとするとFaultExceptionが発生する

System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(System.ServiceModel.Channels.Message reply, System.ServiceModel.Channels.MessageFault fault, string action, System.ServiceModel.Channels.MessageVersion version, System.ServiceModel.Channels.FaultConverter faultConverter) + 0x124 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannel.HandleReply(System.ServiceModel.Dispatcher.ProxyOperationRuntime operation, ref System.ServiceModel.Dispatcher.ProxyRpc rpc) + 0x147 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannel.EndCall(string action, object[] outs, System.IAsyncResult result) + 0xb2 bytes
System.ServiceModel.dll!System.ServiceModel.ClientBase.ChannelBase.EndInvoke(string methodName, object[] args, System.IAsyncResult result) + 0x1e bytes
PhoneClient.dll!PhoneClient.ServiceReference1.Service1Client.Service1ClientChannel.EndGetFirstAidGuides(System.IAsyncResult result) Line 420 C# PhoneClient.dll!PhoneClient.ServiceReference1.Service1Client.PhoneClient.ServiceReference1.IService1.EndGetFirstAidGuides(System.IAsyncResult result) Line 284 + 0x7 bytes C# PhoneClient.dll!PhoneClient.ServiceReference1.Service1Client.OnEndGetFirstAidGuides(System.IAsyncResult result) Line 292 + 0x2 bytes C# System.ServiceModel.dll!System.ServiceModel.ClientBase.OnAsyncCallCompleted(System.IAsyncResult result) + 0x20 bytes
System.ServiceModel.dll!System.ServiceModel.AsyncResult.Complete(bool completedSynchronously) + 0x66 bytes
System.ServiceModel.dll!System.ServiceModel.AsyncResult.Complete(bool completedSynchronously, System.Exception exception) + 0xe bytes
System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.CallComplete(bool completedSynchronously, System.Exception exception) + 0x8 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishSend(System.IAsyncResult result, bool completedSynchronously) + 0x99 bytes
System.ServiceModel.dll!System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.SendCallback(System.IAsyncResult result) + 0x1a bytes
System.ServiceModel.dll!System.ServiceModel.AsyncResult.Complete(bool completedSynchronously) + 0x66 bytes
System.ServiceModel.dll!System.ServiceModel.AsyncResult.Complete(bool completedSynchronously, System.Exception exception) + 0xe bytes
System.ServiceModel.dll!System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnGetResponse(System.IAsyncResult result) + 0x52 bytes
System.Windows.dll!System.Net.Browser.ClientHttpWebRequest.InvokeGetResponseCallback.AnonymousMethod__8(object state2) + 0x1b bytes mscorlib.dll!System.Threading.ThreadPool.WorkItem.WaitCallback_Context(object state) + 0x18 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x63 bytes
mscorlib.dll!System.Threading.ThreadPool.WorkItem.doWork(object o) + 0x47 bytes mscorlib.dll!System.Threading.Timer.ring() + 0x70 bytes

エラー:サーバーが内部エラーのために要求を処理できませんでした。エラーの詳細については、例外情報をクライアントに送り返すために、サーバー上のIncludeExceptionDetailInFaults(ServiceBehaviorAttributeまたは構成動作のいずれか)をオンにするか、Microsoft .NET Framework 3.0 SDKドキュメントに従ってトレースをオンにしてくださいサーバートレースログを検査します。

私はWCFサービスと通信しているWindows Phone 7アプリケーションを開発中です。私は既に1つの方法の中でそれを動作させました。だから私はそれが可能です。ここで

は今WCFサービス

public partial class FirstAidGuides : PhoneApplicationPage 
{ 
    public FirstAidGuides() 
    { 
     InitializeComponent(); 
     ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client(); 
     sc.GetFirstAidGuidesCompleted += new EventHandler<ServiceReference1.GetFirstAidGuidesCompletedEventArgs>(sc_GetFirstAidGuidesCompleted); 
     sc.GetFirstAidGuidesAsync(); 
    } 

    void sc_GetFirstAidGuidesCompleted(object sender, ServiceReference1.GetFirstAidGuidesCompletedEventArgs e) 
    { 
     FirstAidGuideText.Text = e.Result[0].Text; 
    } 
} 

を呼び出し、私のクラスで、私はちょうど私の結果から、テキストブロックで記述されたテキストを取得しようとしています。

これはWCFサービスのインターフェイスです。

[ServiceContract] 
public interface IService1 
{ 

    [OperationContract] 
    long CreateCall(string phoneNumber, double longtitude, double langtitude); 

    [OperationContract] 
    List<Model.FirstAidGuide> GetFirstAidGuides(); 
} 

データベースからデータをプルするサービスクラスのメソッドです。

public List<Model.FirstAidGuide> GetFirstAidGuides() 
    { 
     DataClasses1DataContext db = new DataClasses1DataContext(); 

     var firstAidGuides = (from f in db.FirstAidGuides select f); 
     List<Model.FirstAidGuide> list = new List<Model.FirstAidGuide>(); 

     foreach (var guide in firstAidGuides.ToList()) 
     { 
      Model.FirstAidGuide fa = new Model.FirstAidGuide(); 
      fa.FirstAidId = guide.FirstAidId; 
      fa.Title = guide.FirstAidTitle; 
      fa.Text = guide.FirstAidText; 
      fa.LastUpdated = (DateTime)guide.LastUpdated; 
      list.Add(fa); 
     } 
     return list; 
    } 

便宜上、 FirstAidGuideクラス。

[DataContract] 
public class FirstAidGuide 
{ 
    [DataMember] 
    private string _title; 
    [DataMember] 
    private string _text; 
    [DataMember] 
    private DateTime _lastUpdated; 
    [DataMember] 
    private long _firstAidId; 

    public long FirstAidId 
    { 
     get { return _firstAidId; } 
     set { _firstAidId = value; } 
    }  

    public DateTime LastUpdated 
    { 
     get { return _lastUpdated; } 
     set { _lastUpdated = value; } 
    }  

    public string Text 
    { 
     get { return _text; } 
     set { _text = value; } 
    }  

    public string Title 
    { 
     get { return _title; } 
     set { _title = value; } 
    } 
} 

私は単純に何もすることはできません。私はWCFサービスからの応答を処理できないという方向で私を指摘するFaultExceptionを取得しています。

ご協力いただければ幸いです。

+0

パブリックプロパティではなく、バッキングフィールドにDataMember属性があるのはなぜですか? –

+0

私は正直に分かりません。それは感じているすべてのものを試した後、必死の動きでした:) –

+0

あなたはそれらをバッキングフィールドではなくプロパティに戻したいと思うでしょう。あなたの取得するFaultExceptionは何ですか? –

答えて

-1

問題は、この行にあった:このような何か

foreachの(firstAidGuides.ToList中のvarガイド())

どうやら(.ToListを呼び出すことは)全部のクラッシュを作りました。 .ToList()を単に削除するだけです。

1

WCFサービスでtracingを有効にして、トレースを調べてエラーの内容を調べることはできますか。また

<serviceDebug includeExceptionDetailInFaults="true" /> 
+0

> \t PhoneClient.dll!PhoneClient.ServiceReference1.Service1Client.Service1ClientChannel.EndGetFirstAidGuides(System.IAsyncResult結果)ライン420 \t C# これは私のために問題を引き起こすように見えるラインです。 –

1

は、私はWCF上で行う傾向にあることはTry...Catchブロックでの私の[OperationContract]メソッド内のすべてをラップすることですエラーの完全なスタックトレースを取得するには、以下のプロパティを設定します。キャッチされた例外とすべての内部例外のスタックトレースを解き、それを文字列としてFaultExceptionのメッセージに貼り付けます。その後、私はそれをsoap境界に再スローします。

public static string GetDebugString(this Exception ex) 
{ 
    var builder = new StringBuilder(); 
    GetDebugString(ex, builder); 
    while ((ex = ex.InnerException) != null) 
    { 
     GetDebugString(ex, builder); 
    } 
    return builder.ToString(); 
} 


private static void GetDebugString(Exception ex, StringBuilder builder) 
{ 
    builder.AppendLine(ex.GetType().Name); 
    builder.AppendLine(); 
    builder.AppendLine(ex.Message); 
    builder.AppendLine(); 
    builder.AppendLine(ex.StackTrace); 
    builder.AppendLine(); 
} 

[OperationContract] 
public void Foo() 
{ 
    this.MakeSafeCall(() => this.UnsafeFoo()); 
} 

public void Unsafe() 
{ 
    // do stuff 
} 

private void MakeSafeCall(Action action) 
{ 
    try 
    { 
     action(); 
    } 
    catch (Exception ex) 
    { 
     throw new FaultException(ex.GetDebugString()); 
    } 
} 
関連する問題