Groups | Blog | Home
all groups > dotnet web services > june 2007 >

dotnet web services : Library differences when adding Web Reference


Gustaf
6/29/2007 5:11:49 PM
Here's what happens: I got a Web Service installed locally on my IIS. Then I got a client project, which will call this service. But when I add the Web Reference to the Web Service, and look at the imported classes with Object Browser, there are classes missing. How can that be?

The classes in question are of course public, and I see them in Object Browser in the Web Service project. The classes are auto-generated from an XSD file, using the xsd.exe tool (but that shouldn't matter).

John Saunders [MVP]
6/29/2007 5:49:52 PM
[quoted text, click to view]

What kind of classes are missing? For instance, are SOAP Fault classes
missing? If so, that's because .NET ignores SOAP Faults as far as processing
a WSDL is concerned.
--
John Saunders [MVP]
Gustaf
7/2/2007 12:00:00 AM
[quoted text, click to view]

Thanks for helping. The one class I see is missing, is the class that corresponds to the root element type in the schema. I noticed that only complex types get their class representations when generating code with xsd.exe, not element declarations. So, in this case

<xs:element name="MyRoot" type="MyRootType"/>

<xs:complexType name="MyRootType">
<xs:sequence>
<xs:element name="MyItem" type="MyItemType"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

there is no MyRoot class generated, but a MyRootType class. In my case, it's the MyRootType class that's missing when I import the classes using a Web Reference.

John Saunders [MVP]
7/2/2007 11:22:51 AM
[quoted text, click to view]

Do you use the MyRootType directly? Does your Web Reference code compile?

I've noticed that XSD.EXE will only include types it thinks are being used,
and this isn't always the same set of types you think are being used. In one
case, I had to play around for days to get it to include the types I wanted.

As an experiment, could you add a web method that returns a MyRoot and then
see what that generates in the Web Reference?
--
John Saunders [MVP]
John Saunders [MVP]
7/4/2007 1:32:50 PM
[quoted text, click to view]

This last part sounds like a clue. Are you using document or rpc style,
wrapped or literal? Can you post the <wsdl:binding> section of your WSDL
file (or the whole thing if you can)? I've seen this business of an inner
element being returned, and I think it had to do with wrapped vs. literal.

I'd like to create a reproducer for this, because I can see it as an issue
that will come up for many developers. Unfortunately, I'm tied up at the
moment and may not get to it in the next couple of days.
--
John Saunders [MVP]
Gustaf
7/4/2007 4:08:26 PM
[quoted text, click to view]

I can set up the Web Reference without complaints, so I suppose that part is okay as far as Visual Studio is concerned. The Web Service project compiles, and if I check Object Browser from that project, I see all the classes I want. Then when I include the Web Reference to this Web Service from another project, one class disappears.

[quoted text, click to view]

I noticed that too. If you include an element with no parent in the schema, it's not represented in the generated code. Naturally, the root element has no parent, but the class for the root element type is indeed generated (with the XmlRootAttribute attribute), and is recognized in the Web Service project.

So it appears to me that whatever happens, happens when setting up the Web Reference.

[quoted text, click to view]

It generates a method with a return value of the class one level below the root element. But nevemind that now. After so much time spent on this, I had to stop working on it. Thanks anyway.

Gustaf

Gustaf
7/6/2007 4:17:56 PM
[quoted text, click to view]

I have now simplified the schema and stripped it from all sensitive information, so I can make it public here, for you and others to test. I have also tested that the schema produces the result described. Here's the schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns="http://example.org/Response"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example.org/Response"
elementFormDefault="qualified">

<xs:complexType name="ResponseType">
<xs:sequence>
<xs:element name="ErrorCode" type="xs:string"/>
<xs:element name="ErrorMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="ResponseListType">
<xs:sequence>
<xs:element name="Response" type="ResponseType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:element name="ResponseList" type="ResponseListType"/>

</xs:schema>

And here's step-by-step instruction on how you produce the same error:

1. Generate a file with classes from the schema with the xsd.exe tool.
2. Create a new Web Service project, and import the generated file.
3. Add a WebMethod that returns a ResponseListType object:

[WebMethod]
public ResponseListType GetResponseList() {
return null;
}

4. Using Object Browser, confirm that the ResponseListType class is included. It is.
5. Create a Console Application project and add a web reference to the web service.
6. Using Object Browser, look for the ResponseListType class among the classes imported by the web reference. It won't be there.

Gustaf



AddThis Social Bookmark Button