WCFサービスからクライアントアプリケーションにカスタム例外をスローしようとしています。私はこれに関連すると思うほど多くのコードを記述しようとします。WCFサービスがクライアントにカスタム例外をスローする
例外:
using System.Runtime.Serialization;
namespace App.Exceptions
{
/// <summary>
/// General App exception
/// </summary>
[DataContract]
public class AppException : System.Exception
{
private string strMessage = "An unknown exception occurred";
/// <summary>
/// Creates a new instance of a App Exception
/// </summary>
public AppException()
{ }
/// <summary>
/// Creates a new instance of a App Exception
/// </summary>
/// <param name="Message">Message to send as exception</param>
public AppException(string Message)
{ strMessage = Message; }
public override string Message
{ get { return strMessage; } }
}
}
サービスコード:
(...)
using App.Exceptions;
namespace App.Services
{
public class Service1 : IService1
{
public Service1()
{ }
public void TestFunction()
{
throw new AppException();
}
}
}
ServiceInterface:
(...)
namespace App.Services.Interfaces
{
[ServiceContract]
public interface IService1
{
[OperationContract]
void TestFunction();
}
}
クライアント:
(...)
using App.Exceptions;
(...)
try
{
service.TestFunction();
}
catch (AppException ex)
{
}
すべて正常に動作し、関数がサービスで呼び出され、例外がスローされます。参照は、クライアントとサーバーのいずれかでまったく同じです。私は喜んで、AppException
は同じネームスペースで参照されているので、大丈夫です。
私は別の例外を取得し、実際にそれはので、私は本当にブレークポイントをキャッチに設定された理由を理解していないよと異なる場合だけ見るためにFalseに設定も<serviceDebug includeExceptionDetailInFaults="True" />
を設定し、するサービスapp.config
に試してみましたAppException
は決してヒットしません。
EDIT:
サービスの設定:
<service name="App.Services.Service1">
<endpoint address="" binding="basicHttpBinding" contract="App.Services.Interfaces.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/App.Services/Service1/" />
</baseAddresses>
</host>
</service>
クライアントの設定:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8733/Design_Time_Addresses/App.Services/Service1/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="Services.IService1" name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
[クライアントへのWCF Webサービスカスタム例外エラー](https://stackoverflow.com/questions/1369882/wcf-web-service-custom-exception-error-to-client) – Marisa
Iの可能性のある重複それもやってみた。 AppException catchは決してヒットしません。 – rgomez
catch(AppException ex)またはcatch(FaultException ex)を使用しましたか?前者はうまくいかず、後者はすべきです。 –
Marisa