简体   繁体   中英

Error propagation from wcf to asmx

I have a web method ( .asmx web service ), which consume another service method ( 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> . 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. However, this is not advisable since the web service is been already live and is been used other legacy application at client side.

Can someone advise me on how to handle wcf custom exceptions within .asmx web method ?. 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.

Note: I am trying to achieve a staged decommission approach where individual .asmx web service shall be replaced with its wcf counterpart. And this is to prove the stakeholders on how both web service and wcf service can coexists without impacting business. 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. This is because basicHttpBinding uses SOAP 1.1 to communicate with clients, and there is no SOAP 1.2 stack in .net2.

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. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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