麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

WCF服務的異常消息

2019-11-17 01:49:51
字體:
來源:轉載
供稿:網友

WCF服務的異常消息

原創地址:http://www.companysz.com/jfzhu/p/4055024.html

轉載請注明出處

WCF Service發生異常的時候,客戶端一般只能看見這樣一個錯誤:“The server encountered an error PRocessing the request”,而異常的類型和引起異常的代碼都沒有顯示,究其原因是出于安全考慮。如果想要暴露這些異常信息的細節給客戶端,只需要在服務器的配置文件上修改<serviceDebug includeExceptionDetailInFaults="true" />。

(一)SOAP WCF Service的異常

(1) 當serviceDebug includeExceptionDetailInFaults="false"

IDemoService.cs:

using System.ServiceModel;namespace WCFDemo{        [ServiceContract(Name = "IDemoService")]    public interface IDemoService    {        [OperationContract]        int Divide(int numerator, int denominator);    }}

DemoService.cs:

using System;using System.ServiceModel.Activation;namespace WCFDemo{    [aspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]    public class DemoService : IDemoService    {        public int Divide(int numerator, int denominator)        {            return numerator / denominator;        }    }}

web.config

<?xml version="1.0"?> <configuration>     <system.web>       <compilation targetFramework="4.0" />     </system.web>    <system.serviceModel>       <services>         <service name="WCFDemo.DemoService" behaviorConfiguration="metaBehavior">           <endpoint address="DemoService" binding="basicHttpBinding" contract="WCFDemo.IDemoService" />           <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>           <host>             <baseAddresses>               <add baseAddress="http://localhost:8080"/>             </baseAddresses>           </host>         </service>       </services>         <behaviors>             <serviceBehaviors>                 <behavior name="metaBehavior">                     <serviceMetadata httpGetEnabled="true" />                     <serviceDebug includeExceptionDetailInFaults="false" />                 </behavior>             </serviceBehaviors>         </behaviors>         <serviceHostingEnvironment mult

建立一個Windows Client,Form1.cs:

private void buttonCalculate_Click(object sender, EventArgs e) {     DemoServiceReference.DemoServiceClient demoServiceClient = new DemoServiceReference.DemoServiceClient();     textBoxResult.Text = demoServiceClient.Divide(Convert.ToInt32(textBoxNumerator.Text), Convert.ToInt32(textBoxDenominator.Text)).ToString(); } 

Client app.config

<?xml version="1.0" encoding="utf-8" ?> <configuration>     <system.serviceModel>         <bindings>             <basicHttpBinding>                 <binding name="BasicHttpBinding_IDemoService" />             </basicHttpBinding>         </bindings>         <client>             <endpoint address="http://169.254.14.147:8080/DemoService.svc/DemoService"                 binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDemoService"                 contract="DemoServiceReference.IDemoService" name="BasicHttpBinding_IDemoService" />         </client>     </system.serviceModel> </configuration>

在正常情況下的消息為:

image

image

Request Body:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">  <s:Body>    <Divide xmlns="http://tempuri.org/">      <numerator>100</numerator>      <denominator>10</denominator>    </Divide>  </s:Body></s:Envelope>

Response Body:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">  <s:Body>    <DivideResponse xmlns="http://tempuri.org/">      <DivideResult>10</DivideResult>    </DivideResponse>  </s:Body></s:Envelope>

在發生異常時:

image

image

Request Header:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">  <s:Body>    <Divide xmlns="http://tempuri.org/">      <numerator>100</numerator>      <denominator>0</denominator>    </Divide>  </s:Body></s:Envelope>

Response Body:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">  <s:Body>    <s:Fault>      <faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode>      <faultstring xml:lang="en-US">The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the &lt;serviceDebug&gt; configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.</faultstring>    </s:Fault>  </s:Body></s:Envelope>

(2)當serviceDebug includeExceptionDetailInFaults="true"

可以看到異常的消息為”Attempted to divide by zero.”

image

response body:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">  <s:Body>    <s:Fault>      <faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode>      <faultstring xml:lang="en-US">Attempted to divide by zero.</faultstring>      <detail>        <ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">          <HelpLink i:nil="true"/>          <InnerException i:nil="true"/>          <Message>Attempted to divide by zero.</Message>          <StackTrace>            at WCFDemo.DemoService.Divide(Int32 numerator, Int32 denominator)&#xD;            at SyncInvokeDivide(Object , Object[] , Object[] )&#xD;            at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp; outputs)&#xD;            at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)&#xD;            at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)&#xD;            at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)&#x
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 康妮卡特欧美精品一区 | 香蕉视频破解 | 99欧美视频 | 免费小毛片 | 成人免费一区二区 | 欧美成人精品不卡视频在线观看 | 久久精品视频69 | 思思久而久而蕉人 | 99精品视频一区二区三区 | 午夜色片 | 黄色大片在线免费看 | 久久艹精品视频 | 久久一级 | 国产成年人网站 | 精品国产一区在线观看 | 99在线免费观看视频 | 精品国产一区二区三区四区在线 | 成人午夜毛片 | 中文字幕一区二区三区久久 | 看免费5xxaaa毛片 | 激情综合网俺也去 | 久久久久一区二区三区 | 成人在线精品视频 | wwwcom国产| 久久久久久亚洲综合影院红桃 | 免费观看一级黄色片 | 久久国产成人精品国产成人亚洲 | 久久欧美亚洲另类专区91大神 | 中文字幕 亚洲一区 | 久色亚洲 | 国产一区亚洲 | 成人18网站 | 国产99久久精品一区二区300 | 国产小视频在线 | 国产精品久久久久久久亚洲按摩 | 曰韩在线视频 | 中文字幕涩涩久久乱小说 | 免费国产羞羞网站视频 | 国产91精品久久久久久久 | 欧美精品一区二区久久 | 国产一区二区三区视频在线观看 |