Wednesday, April 29, 2009

Interoperability Gotcha: Visual Studio 2008 Proxy Flavours

@YaronNaveh

The following interoperability issue can happen with a .Net 3.5 clients and older web services from various platforms (including Java. and .Net)

Everyone knows that Visual Studio 2008 has a build-in support for WCF which is the latest generation of Microsoft soap stack. By default, when writing web service clients in VS 2008 a WCF-flavored proxy is generated. However WCF only supports a subset of XML schema and WSDL patterns. For example it does not support RPC/Encoded WSDLs and XML attributes. Many older WSDLs use RPC/Encoded. With such WSDLs WCF is supposed to gracefully downgrade itself to .Net 2.0 which does support these WSDLs. I have noticed that in some cases this does not happen correctly. The result can be web service methods returning null instead of values.

The solution for such cases is to manually instruct VS 2008 to use its backward compatible proxy. All you need to do is:

1. Press the "Add Service Reference" as usual



2. Press the "Advanced..." button



3. Select "Add Web Reference..."



4. Use the good old .Net 2.0 proxy flavours

@YaronNaveh

What's next? get this blog rss updates or register for mail updates!

7 comments:

ömer arslan said...

thanks, good article

Mayra Lizbeth said...

Hi, i have the same problem but i'm using framework 2.0 with VS2005. It ahppens when i change the web reference in the web.config. My web service works fine but in c# the response is null, could you help me please?

Yaron Naveh (MVP) said...

Hi Mayra

If you use Vs2005 you can only do add web reference anyway, so the problem is other.

Mayra Lizbeth said...

i added the reference using Add Web Reference, but this reference can change in the future. When i added the web reference, in the web.config is created a section called appSetting, here i chaged the url because this reference is dynamic. When i run my web site, the call to the web service is ok but the value that the web method returns is null. My web service is not written in c# is in another languaje but it shows me the response in the server console, with this i'm sure that the web site is invoking my web service but the variable in C# that take the value of the response is null or empty. Some idea ?

Thanks for your atention.

Yaron Naveh (MVP) said...

use a tool like fiddler to look at the soap response that comes back and see if it complies with the wsdl.

Also try to set up a .net service from the same wsdl and see how the soap it returns is different.

Anonymous said...

Thanks, it was helpful for me.
This advice resolves my problem with VS2008 web serviice client.

Kevin - NZ said...

Fixed my problem nicely - with one wrinkle.

Visual Studio 2010 has a nasty habit of crashing when adding Web References for secure servers. It displays streams of HTTPS Security Warnings, then terminates. Microsoft have acknowledged this is a bug and promise to fix it in VS 2012 or whatever.

In the meantime, the workaround is, as soon as the warnings start to appear, quickly click Yes, until all the dialogs are dismissed. Then you can add the Reference normally.