Geeks With Blogs
blog.davidbarrett.net ///<summary>Just a lot of random technical stuff, really.</summary>

I ran across this trying to interop with a Peoplesoft web service using WCF.  If you've ever worked with Peoplesoft web services, you'll know that the contracts that are spun up are just plain wacky.  Arrays embedded within arrays embedded within still more arrays ... simple types represented as a complex type, like a string represented as a typeShape with a .value property ... and more goodness!

Anyhow, I generated my service reference from within Visual Studio and attempted to interop with the service ... but got this exception.  After a bit of googling, turns out WCF can barf on unbounded sequences in schemas, especially when there are arrays embedded within arrays.  Well, technically, this is really an XmlSerializer issue, and when svcutil.exe (or Visual Studio 2008 WCF functionality, in my case) creates .Net classes to represent the schemas in the contract, something goes awry and this message is the result.

What's the fix?  Well, it seems like it's a hack, to be honest.

When your schema contains elements that looks like (taken from the original post):

   1: <xs:sequence maxOccurs="unbounded">
   2:   <xs:element ../>
   3: <xs:sequence>

or

   1: <xs:sequence>
   2:  <xs:element maxOccurs="unbounded"/>
   3: <xs:sequence>

... then the fix is to add some "fake" attributes to change the way the classes are generated, as in:

   1: <xs:sequence maxOccurs="unbounded">
   2:   <xs:element ../>
   3: <xs:sequence>
   4: <xs:attribute name="XmlSerializerFix" type="xs:string" />

or

   1: <xs:sequence>
   2:   <xs:element maxOccurs="unbounded"/>
   3: <xs:sequence>
   4: <xs:attribute name="XmlSerializerFix" type="xs:string" />

Seems kinda random, but it works.  Fixed my problem.  I ended up modifying the .xsd files that are created by the service reference (via the WSDL) and then manually running svcutil to re-create the Reference.cs file that also gets created by service reference.  I just have to remember not to update the service reference automatically with Visual Studio, or when the interface does change, I'll have to re-implement this fix, but that's easy enough to do.

Link to the original source for this fix is at http://forums.msdn.microsoft.com/en-US/asmxandxml/thread/e33305c3-b5f6-4922-8a3f-df202088d25a/.

Posted on Wednesday, June 25, 2008 10:58 PM WCF , SOA | Back to top


Comments on this post: WCF: System.InvalidOperationException: Unable to generate a temporary class (result=1)

# re: WCF: System.InvalidOperationException: Unable to generate a temporary class (result=1)
Requesting Gravatar...
We had the same problem and used this hack which worked. Now we are upgrading PS and the new WSDLs have WS-policy assertions that svcutil is choking on. Have you run into issue?
Left by Eric on Oct 03, 2008 1:45 PM

# re: WCF: System.InvalidOperationException: Unable to generate a temporary class (result=1)
Requesting Gravatar...
Not that I recall, Eric. Sorry.
Left by David Barrett on Oct 03, 2008 2:28 PM

Your comment:
 (will show your gravatar)


Copyright © David Barrett | Powered by: GeeksWithBlogs.net