locked
Add Service Reference loses [FaultContract] RRS feed

  • Question

  • User647540711 posted

    If I use Add Service Reference in a WCF client the Fault Contracts are not being included in the generated code. If I use SvcUtil they are. Am I doing something wrong with  Add Service Reference, i.e. missing a setting?

    UPDATE:

    Not sure what the protocol is for renaming a thread but we have determined that this is NOT a client issue; the problem is that the service is not being updated when revisions are published, even after IIS is restarted and the app pool is recycled.

    Sunday, June 9, 2013 10:56 PM

Answers

  • User260886948 posted

    Hi,

    Many people meet the same question as you. When they tried to use the Add Service Reference wizard in Visual Studio, they had a problem: they could not import the fault contracts. But using the Svcutil.exe works.

    The difference between Add Service Reference and Svcutil.exe is that one has the UseSerializerForFaults option easily available to you as a switch on the command line. Using this switch instructs Svcutil.exe to use the XmlSerializer to handle faults instead of the default, which is the DataContractSerializer. In this case, although Svcutil.exe has indicated that the WSDL for the fault is flawed, it continues to import the service operation.

    If you want to enable VS Add Service Reference to do the same thing:

    1. Click Show All Files in the Solution Explorer.
    2. Open the Reference.svcmap file in your service reference.
    3. Set the option <UseSerializerForFaults> to false in Reference.svcmap and save it. (NOTE: Take care NOT to update the service reference, as doing so resets the option to true.)
    4. Open the reference.cs and you should see the operations generated.

    For more information, please try to refer to the following article which tells the details:
    http://blogs.msdn.com/b/ralph.squillace/archive/2011/01/27/technical-note-proxy-classes-different-when-using-svcutil-exe-and-vs-add-service-reference-doubleclick-com-edition.aspx . 

    Hope it can help you.

    Best Regards,
    Amy Peng 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 13, 2013 2:40 AM

All replies

  • User-1972223072 posted

    where is wcf service deployed, is it with in the same solution are deployed some where else.

    Monday, June 10, 2013 2:17 AM
  • User647540711 posted

    It's deployed in a seperate solution Syed.

    Followup:

    If I run svcutil from the assembly folder the Fault Contract properties are included in the generated class. If I run it against the end point url they are not. I obviously need to dig deeper into the scvutil documention because a must be missing a parameter. 

    Monday, June 10, 2013 7:16 AM
  • User-488622176 posted

    Please check this sample : http://www.c-sharpcorner.com/uploadfile/SunilBabuYLV/using-the-fault-contracts-soap-faults-in-wcf-programming/

    I assume you're not using fault contracts the right way. If this does not solve your issue, please post us some code.

    Tuesday, June 11, 2013 4:18 AM
  • User260886948 posted

    Hi,

    Many people meet the same question as you. When they tried to use the Add Service Reference wizard in Visual Studio, they had a problem: they could not import the fault contracts. But using the Svcutil.exe works.

    The difference between Add Service Reference and Svcutil.exe is that one has the UseSerializerForFaults option easily available to you as a switch on the command line. Using this switch instructs Svcutil.exe to use the XmlSerializer to handle faults instead of the default, which is the DataContractSerializer. In this case, although Svcutil.exe has indicated that the WSDL for the fault is flawed, it continues to import the service operation.

    If you want to enable VS Add Service Reference to do the same thing:

    1. Click Show All Files in the Solution Explorer.
    2. Open the Reference.svcmap file in your service reference.
    3. Set the option <UseSerializerForFaults> to false in Reference.svcmap and save it. (NOTE: Take care NOT to update the service reference, as doing so resets the option to true.)
    4. Open the reference.cs and you should see the operations generated.

    For more information, please try to refer to the following article which tells the details:
    http://blogs.msdn.com/b/ralph.squillace/archive/2011/01/27/technical-note-proxy-classes-different-when-using-svcutil-exe-and-vs-add-service-reference-doubleclick-com-edition.aspx . 

    Hope it can help you.

    Best Regards,
    Amy Peng 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 13, 2013 2:40 AM
  • User647540711 posted

    Thanks very much for your efforts to document this solution Amy. I had already tried what you suggested.  Unfortunately it does not solve my problem, which, it develops, is not a problem with FaultContract attributes but one of caching. I was going to add more detail to this thread but wanted to work through to a solution before doing so.

    First we can take the client out of the mix altogether for purposes of testing; I can navigate to the site and look at the wsdl.

    Regardless of the changes I made to the contact, e.g. renaming a method. the changes were not showing up in the results. I tried stopping and restarting IIS. I tried recycling the app pool. I even deleted the dll. Now for the really strange bit: I created another little test service, one with a single method. When I published it the new service had successfully replaced the other one. Then I added a method and published it. The new method was successfully added. The I published the problem service but it did not replace the little test service.

    So my working hypothesis right now is that this is an IIS caching issue that I don't understand. I've certainly not encountered anything similar with web applications. I will continue wokring on it and add to this thread when the problem is corrected.

    Thursday, June 13, 2013 8:28 AM
  • User220959680 posted

    When ever Service is updated/republished make sure that service reference is updated in client application i.e., Update Service context menu in solution explorer.

    Thursday, June 13, 2013 8:50 AM
  • User503812343 posted

    As you said the WCF service is deployed in seprate application. Check the build version of dlls of hosting application is same as you are making add service reference.

    Some time I build the applications in Release mode however while adding reference add it from debug and find nothing updated.

    Check:

    http://dotnetmentors.com/handling-wcf-service-exceptions-using-fault-contracts.aspx

    Thursday, June 13, 2013 10:17 AM
  • User647540711 posted

    Issue resolved. It was related to how the svc file was being named. Like I reported above, I started referring to the wsdl on the site so as to bypass the client while I was sorting out why the changes weren't being reflected in the service.

    Amy's suggestion was the way I decided to go with client updates. Thanks to all.

    Thursday, June 13, 2013 1:15 PM