none
Svcutil.exe issues: generates twice the same elements or generates codes that do not compile RRS feed

  • Question

  • Hello,

    I ran into trouble with svcutil tool. I'm starting from a hand-written WSDL file and want to generate service code out of it. The WSDL file contains references to external schemas (that are given as parameter to svcutil.exe as we are generating from local files).

     

    The first problem occurs when I use the /ser:Auto switch (no /ser switch at all). Some of the classes generated (as partial) are defined multiple times with same fields. The generated code resulting contains errors.

     

    The second issue occurs when I use the /ser:XmlSerializer switch to force svcutil.exe to use the same serializer for all the elements found. Again, the generated code contains errors. I found another thread reporting similar error: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1333449&SiteID=1

     

    The hand-written WSDL files was working fine until I added soap:fault elements in it. After some test, I found what was the pattern.

     

    It seems that when an element is used both in soap:header/soap:body AND in soap:fault in a message, svcutil.exe don't understand that these are the same XML elements. This, however, can be forced by using the /ser:XmlSerializer switch.

     

    However, as stated before, when forcing the XmlSerializer, the generated code contains errors at the annotation level of the operation that can launch the fault.

     

    The error in the code is that the typeof paramter of the FaultContractAttribute annotation refers to the XML file namespace, not the .NET replaced one (specified using the /n switch). On top of this, the FaultMessage don't exist in the generated code, so manually modifying the namespace in the generated code is not sufficent (event if that would not be good, as modification of generated code is not good practice I guess...).


    Some background on the project:

    The aim is to build interoperable code, hence the hand written WSDL file. Services will be implemented both with WCF and Axis2. This is why we would like to solve this not by rearranging the WSDL file, as it must be BP 1.1 compliant and as clean as possilble.

     

    PS: I originally posted this in another part of the forum: http://forums.msdn.microsoft.com/en-US/netfxnetcom/thread/6c321e34-7586-44ef-b7d0-782121b73e70

     

    I don't know why but in this part of the forum, the code looks ugly and the editor complains of my original post beeing too long, so I skiped the code parts...

    Monday, August 4, 2008 7:26 AM

All replies

  • Are you still running into this?

     

    Saturday, August 9, 2008 1:28 AM
  • Yes I do.

     

    For now, as I didn't find any solution, I'm modifying the generated code, removing the heading namespace of the Fault annotation.

    Monday, August 11, 2008 7:30 AM
  • From the post in the other forum, it looks like your wsdl have some problems.

     

     // CODEGEN: Generating message contract since the operation GetQuote is neither RPC nor document wrapped.  

     

    1) Put your headers in a separate message part. 

    2) Rename the "body" message part to "parameters".

    3) Remove references to the message part in the soap:body binding.  (Each of your message should have only one part.  Hence, the soap:body binding will use that one.)

     

    An

    Monday, August 11, 2008 8:41 AM
  • First, thanks for helping!

     

    Doing this generates a code that is a bit different, but the fault annotation is still wrong.

     

    This is what I end up with:

     

    Code Snippet

    // CODEGEN: Generating message contract since the wrapper name (Name) of message GetQuoteRequest does not match the default value (GetQuote)

    [System.ServiceModel.OperationContractAttribute(Action="urn:GetQuote", ReplyAction="*")]

    [System.ServiceModel.FaultContractAttribute(typeof(www.r4egov.eu.data.FaultMessage), Action="urn:GetQuote", Name="FaultMessage")]

    [System.ServiceModel.XmlSerializerFormatAttribute()]

    WsdlToCode.Generated.GetQuoteResponse GetQuote(WsdlToCode.Generated.GetQuoteRequest request);

     

     

    The comment is different, but I can't manage to see what's wrong.

    Monday, August 11, 2008 11:39 AM