简体   繁体   English

从WCF到ASMX的错误传播

[英]Error propagation from wcf to asmx

I have a web method ( .asmx web service ), which consume another service method ( WCF service ). 我有一个Web方法( .asmx web service ),它消耗了另一种服务方法( WCF service )。 However, I now want write more logic within my web method based on the different type of custom exception thrown from the wcf service using FaultContract<T> . 但是,我现在想基于Web方法,使用FaultContract<T>从wcf服务中抛出不同类型的自定义异常,从而在我的web方法中编写更多逻辑。 I may be able to achieve this if I revise the target framework of .asmx web service from 2.0 to 3.x to support generics. 如果将.asmx Web服务的目标框架从2.0修改为3.x以支持泛型,那么我可能能够实现这一目标。 However, this is not advisable since the web service is been already live and is been used other legacy application at client side. 但是,这是不可取的,因为Web服务已经处于运行状态,并且已在客户端被其他遗留应用程序使用。

Can someone advise me on how to handle wcf custom exceptions within .asmx web method ?. 有人可以建议我如何在.asmx Web方法中处理wcf自定义异常吗? I am not too fuss about having generic exception as long as I shall be able to identify the type of wcf fault in my web method. 只要我能够识别Web方法中的wcf错误类型,我就不会对通用异常大惊小怪。

Note: I am trying to achieve a staged decommission approach where individual .asmx web service shall be replaced with its wcf counterpart. 注意:我正在尝试实现一种阶段性的停用方法,其中应将单独的.asmx Web服务替换为其wcf对应项。 And this is to prove the stakeholders on how both web service and wcf service can coexists without impacting business. 这是为了向利益相关者证明Web服务和WCF服务如何共存而不影响业务。 Hope it make sense. 希望有道理。

Because you're restricted to running in .net2 in order to interoperate with a WCF service, that service will have to use basicHttpBinding. 由于只能与.net2一起运行才能与WCF服务进行互操作,因此该服务将必须使用basicHttpBinding。 This is because basicHttpBinding uses SOAP 1.1 to communicate with clients, and there is no SOAP 1.2 stack in .net2. 这是因为basicHttpBinding使用SOAP 1.1与客户端进行通信,并且.net2中没有SOAP 1.2堆栈。

If the service defines fault contracts then this is because the service wants to expose strongly typed exceptions to clients. 如果该服务定义了故障合同,那是因为该服务希望向客户端公开强类型的异常。

However, I don't know exactly what will happen to a .net 2.0 client when receiving these but I suspect your client will just fall over with a .net exception of some kind. 但是,我不确切知道接收到这些消息时.net 2.0客户端会发生什么,但是我怀疑您的客户端会因某种.net异常而崩溃。 If there is anything useful in the exception that you can use to handle I don't know, you will have to test this out yourself. 如果有什么有用的例外可以用来处理我不知道的异常,则必须自己进行测试。

At any rate, there is no nice way I can think of for this to work. 无论如何,我想不出什么好办法。 Hope it helps you. 希望对您有帮助。

You can fix it with some modifications in config file. 您可以通过对配置文件进行一些修改来修复它。 Consider following sample: 考虑以下示例:

 <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="Tajan.Web.UI.Services.UserServiceAspNetAjaxBehavior">
          <enableWebScript />
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="debug">
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
   </behaviors>

 <services>
      <service behaviorConfiguration="debug" name="YOUR_SERVICE_CLASS">
        <endpoint address="" behaviorConfiguration="YOUR_SERVICE_CLASS_Behavior" binding="webHttpBinding" contract="YOUR_SERVICE_CLASS_INTERFACE" />
      </service>

    </services>
  </system.serviceModel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM