0
我試圖抓住WCF sercue所有的異常有/無SSL/TLS或終點,這樣的事情:最佳實踐
try
{
ServiceReference.ServiceClient serviceClient = new ChartLogicServiceClient();
serviceClient.Open();
serviceClient.Login("", "", "");
}
catch (SecurityNegotiationException negotiationException)
{
// Could not establish trust relationship for the SSL/TLS secure channel with authority 'localhost'.
throw;
}
catch (ArgumentException argumentException)
{
// transport wrong config : The provided URI scheme 'https' is invalid; expected 'http'.
//if (argumentException.Message == "The provided URI scheme 'http' is invalid; expected 'https'.\r\nParameter name: via")
throw;
}
catch (MessageSecurityException messageSecurityException)
{
// transport wrong config: The HTTP request was forbidden with client authentication scheme 'Anonymous'.
//- HTTP Request Error
if (messageSecurityException.InnerException.Message == "The remote server returned an error: (403) Forbidden.")
{
throw;
}
else if (messageSecurityException.InnerException.Message == "The remote server returned an error: (404) Forbidden.")
{
throw;
}
}
catch (EndpointNotFoundException endpointNotFoundException)
{
// no endpoint was found or IIS on server was turned off
}
我可以檢查可用的WCF服務,而無需調用任何方法(我試過打開()但不工作)?不知道我是否從WCF服務中捕獲了所有例外情況?我的目的是,如果客戶端通過SSL/TSL或無端點獲得了wcf異常,我應該運行一個小型的實用程序控制臺來修復客戶端上的app.config,以便與wcf端點映射。 我真的需要你的建議。謝謝
謝謝,我使用GET WebRequest,WebResponse,它工作正常 –