Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / August 2004

Tip: Looking for answers? Try searching our database.

SOAP XML serialization incompatibilites in Visual Studio .NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
martin.skarsaune - 20 Aug 2004 15:39 GMT
We have some SOAP compatilibility issues with Visual Studio .NET.

Procedure:
1. Add web reference by importing WSDL from an external system
2. Generate C# classes
3. Try to invoke the remote service

Problem 1: Wrapping in arrays
 If the WSDL file includes a repeating element:
   <xsd:element name="blabla" maxOccurs="unbounded">
 
 When we invoke the service in .NET, the SOAP message will include an extra
level of array

  <array.....[3]>
    <blabla>...</blabla>
    <blabla>...</blabla>
    <blabla>...</blabla>
  </array>

 The remote system is unable to process the message (probably DOM based
algorithm)

Problem 2: Restrictions

 
The WSDL defines custom types with restrictions...

    <xsd:simpleType name="String50">
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="1"/>
            <xsd:maxLength value="50"/>
        </xsd:restriction>
    </xsd:simpleType>

...and use them in the WSDL

    <xsd:element name="blabla" type="String50">

(I leave namespaces out for simplicity)

When the .NET generated code maps field "blabla" to type "xsd:string".
When the remote server includes <blabla xsd:type="String50">hello
helo</blabla> in
it's response then .NET is not able to parse the result

Problem 3:

<wsdl:import> does not seem to work. We got around this problem by applying
a "flatten" transformation to the WSDL
before importing it in visual studio.

Do you know any workarounds for these problems?

Regards

Martin Skarsaune
William Stacey [MVP] - 20 Aug 2004 17:42 GMT
May we see the Transfer object (class) that contains the array or a piece of
the code?

Signature

William Stacey, MVP

> We have some SOAP compatilibility issues with Visual Studio .NET.
>
[quoted text clipped - 52 lines]
>
> Martin Skarsaune
martin.skarsaune - 23 Aug 2004 08:43 GMT
Hello!

Thanks for the rapid response! I'm afraid I cannot give the real source, but
I included this innocent example in the source, and ran it through the same
process as described in the previous post.  

Wsdl:

            <xsd:complexType name="answer">
                <xsd:sequence>
                    <xsd:element name="topic" type="xsd:string"/>
                    <xsd:element name="grade" type="xsd:string"/>
                </xsd:sequence>
            </xsd:complexType>

C#:
       /// <remarks/>
       public answer[] answers;

Doing this little exercise gave me some more understanding of the problem
and a possible theory:

1. Visual Studio sees that the element has maxOccurs="unbounded"
2. Array is chosen as the data structure for repeating elements in C#
3. Array fields in C# are probably serialized/deserialized to SOAP arrays by
convention

So how can we get around this problem?
1. Do you know any metadata curses we could insert in the generated classes
to avoid using SOAP arrays? This is of course not an optimal solution, as we
would have to repeat this manual process every time the services are
changed....
2. Are there any global settings we could use to avoid using SOAP arrays?
(Might give problems if we need to integrate with other servers using SOAP
arrays)

Thanks!

Martin

> May we see the Transfer object (class) that contains the array or a piece of
> the code?
[quoted text clipped - 57 lines]
> >
> > Martin Skarsaune
William Stacey [MVP] - 23 Aug 2004 13:49 GMT
How do you want the resultant xml to look?  Small example would help.
Cheers!

Signature

William Stacey, MVP

> Hello!
>
[quoted text clipped - 97 lines]
> > >
> > > Martin Skarsaune
Dino Chiesa [Microsoft] - 25 Aug 2004 05:21 GMT
> We have some SOAP compatilibility issues with Visual Studio .NET.
>
[quoted text clipped - 19 lines]
>  The remote system is unable to process the message (probably DOM based
> algorithm)

Where did you get the WSDL?  Are you sure the remote service conforms to the
WSDL?

If you want to eliminate the extra element that wraps the list, you can
decorate the array item with an XmlElement attribute, instead of an XmlArray
+ XmlArrayItem attribute.

eg, serializing this:

 public class ArrayAsList {

   [XmlElement(Type=typeof(string))]
   public ArrayList LineItem;

   public ArrayAsList() { LineItem= new ArrayList(); }

   public void Add(string x) {
     LineItem.Add(x);
   }
 }

Will give you:
      <LineItem>string</LineItem>
      <LineItem>string</LineItem>

while serializing this:

 public class WrappedArray {

   [XmlArray("List")]
   [XmlArrayItem("LineItem", Type=typeof(string))]
   public ArrayList LineItem;

   public WrappedArray() { LineItem= new ArrayList(); }

   public void Add(string x) {
     LineItem.Add(x);
   }
 }

will give you:
      <List>
         <LineItem>string</LineItem>
         <LineItem>string</LineItem>
       </List>

> Problem 2: Restrictions
>
[quoted text clipped - 17 lines]
> helo</blabla> in
> it's response then .NET is not able to parse the result

The service is using SOAP serialization.  Are you sure the WSDL matches the
service?  .NET does this, but the generated proxies will work only if the
WSDL agrees with the service implementation.

> Problem 3:
>
> <wsdl:import> does not seem to work. We got around this problem by
> applying
> a "flatten" transformation to the WSDL
> before importing it in visual studio.

You need to include each item on the command line of wsdl.exe in order to
generate properly.
I don't believe you can do this from VS.    Just go to the command line, and
then add the resulting source file into your VS project.

> Regards
>
> Martin Skarsaune

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.