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 / February 2005

Tip: Looking for answers? Try searching our database.

Interop questions (nil/null value/reference)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mflanagan@RemoveThis.MJFlanagan.com - 19 Feb 2005 18:52 GMT
I think I've figured out my interop problems, but I'd like some
confirmation that I'm not going down the wrong path.

I'm connecting to a web service over which I have no control, and it's
written in Java.  My client is written in C#.  Several of the WSDLs
use nil char, nil dateTime, nil decimal (that is, they all use
'nillable', they do not use occurs=0) for many of the response
variables. Therefore, I have to do something in my proxy class to
handle nil values, otherwise the XML deserializer chokes on the
'nil="true"' values that come back for such types.

It seems that I can modify the proxy class in one of these ways (or a
combo), depending on how I need to use the proxy class:

1.  Change all the types in the proxy class for the corresponding XML
variables to "string," and handle any conversion appropriately after I
get the response back.  That would mean, for example, that a variable
declared as Decimal in the proxy class would be changed (by hand) to
string, and then, when I wanted to use the variable, I would do
something like:

if ((null != ProxyObj.proxyVar) && ("" != ProxyObj.proxyVar))
    System.Datetime myDateTimeOustideProxyClass =
       Convert.ToDatetime(ProxyObj.proxyVar);
else
    System.Datetime myDateTimeOustideProxyClass = Datetime.MinVal;

2. Use the technique described in:
http://blogs.msdn.com/smguest/archive/2004/05/07/128113.aspx
This article suggests creating a new class that shadows the value
types that cannot be nilable.  Sort of a proxy class for the value
types in the proxy class.

My two questions:

1.  Am I pointed anywhere near the right direction?

2.  Is there an easier workaround for this?

3.  Any ideas on automating (or at least easing the burden of)
manually modifying the proxy class whenever I generate a new one (or
refresh an existing one)?

Thanks.

Michael
Keenan Newton - 20 Feb 2005 21:12 GMT
My humble opinion  I think Simon has got it right  I would go with his
last idea about using the complexType.  Yes some work, but once it is
done, it's done.
erymuzuan - 21 Feb 2005 11:00 GMT
Well , I agree with Simon's approach but i think it's too much for me.
Especially when it involves a complex schema, as most situation in
document based messaging. I would normally use the types (as defined in
the WSDL) and create C# objects using XSD.exe( Version 2.0 handels this
better with Nullable<type>) . The other way is using some sort of
mapping tool. In my case I use Altova XMLSpy to generate the codes.
which does a more complex and proper mapping than XSD.exe. which is
basically you manually control the soap object serialization.

regards
erymuzuan mustapa

> My humble opinion  I think Simon has got it right  I would go with his
> last idea about using the complexType.  Yes some work, but once it is
> done, it's done.
mflanagan@RemoveThis.MJFlanagan.com - 22 Feb 2005 02:53 GMT
>My humble opinion  I think Simon has got it right  I would go with his
>last idea about using the complexType.  Yes some work, but once it is
>done, it's done.

Okay, but you can do this only if you control the web service.  I
don't, so I cannot change what the web service sends me.
Dino Chiesa [Microsoft] - 22 Feb 2005 05:50 GMT
This sample shows one approach to handling nillable types that correspond to
.NET Value types, on the client side.
http://cheeso.members.winisp.net/srcview.aspx?dir=xml-serialization&file=XsiNilD
ate.cs


The sample is framed as an XML serialization app.  To use it in a webservice
client, what you would do is modify the generated proxy so that instead of
returning TypeA, it returns your hand-coded TypeA_Memento thing (See the
example).   It wouldn't be hard to parse a type, either in XSD or in C#, and
mechanize the production of the memento.

It does tend to complexify the programming model on the client side, of
course, because now ya gotstabe checkin all those value types to see if they
are valid or not before using them.  Eh, that's the cost of doing business,
though, isn't it?

-D

>>My humble opinion  I think Simon has got it right  I would go with his
>>last idea about using the complexType.  Yes some work, but once it is
>>done, it's done.
>
> Okay, but you can do this only if you control the web service.  I
> don't, so I cannot change what the web service sends me.

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.