Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

Strange things can happen when mixing frameworks, operating systems and programming languages. However, web services are meant to be portable and language agnostic, yet things don't always work out as intended. I've been seeing an issue where a C# .Net client has been failing to generate web service proxies for a JAXWS service running in WebLogic, but after a considerable time debugging the issue was able to resolve it.

The error was coming from the Svsutil.exe and looked like this...
 Error
Custom tool error: Failed to generate code for the service reference 'xxxx'. Please check other error and warning messages for details.
Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Object reference not set to an instance of an object.
Path to Error Source: //wsdl:definitions[@targetNamespace='urn:xxxx']/wsdl:portType[@name='xxxx']


The key message there was "Error: Object reference not set to an instance of an object.". Most other reported cases of Svcutil.exe failing to import a WSDL were for other reasons and didn't help me, but I did stumble upon this archived post which discussed a missing "elementFormDefault" element in the XML Schema definition. That gave me an idea.

There were actually a few more errors, but they all seemed to be due to earlier errors and warnings.
csharperr.png




When looking through the WSDL of the service I wanted to import, I didn't see anything complicated and it seemed to only use custom XML types from a "common" schema used by many other web services. That schema was actually being generated from POJOs so there was no source XSD to work with. Further, this schema being common was meant to be included into other schemas and didn't have its own namespace, so I didn't want to use a qualified element form for it (as suggested in the link I found).

My solution was to create a package-info.java file within the package that had my POJOs and simply set elementFormDefault to UNQUALIFIED, its content was something like this...
 Java
@javax.xml.bind.annotation.XmlSchema(namespace = "", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED)
package xxxx;


After recompiling the service and deploying it again, Svcutil.exe reported no errors and was able to generate the web service proxy! It looked like whatever default value that JAX-WS was using was incompatible with the .Net side of things and an explicit qualified/unqualified form had to be specified.

In my case the JAXWS service was made via the JWS file method, not from a WSDL. For more information see: Programming the JWS File.

-i

Skip down to comments...
A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. If you spot something out of place, please do let me know.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
 
comments powered by Disqus
Other posts you may like...