By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,888 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,888 IT Pros & Developers. It's quick & easy.

WebReference and ServiceDescriptionImporter failing to generate code

P: n/a
I am having a problem generating some soap proxies dynamically using
almost the exact same code as in the MSDN sample.

It has very few differences, mainly I had to manipulate the document to
remove the Any tags that caused 400+ validation warnings but even after
getting the WebReference object ValidationWarnings to 0, it says
NoCodeGenerated in its warning and doesn't generate the code.

I can't see any other errors when I debug it so I am totally confused.
If I comment out the line that sets the soap version to 1.2 it works
fine, but I don't understand why it doesn't work and even more
concerning than that is how do I programmatically find out why it
failed? I think it may be that the document isn't valid for soap 1.2
but no exceptions are thrown, no errors explaining why it is invalid,

I think it may be that the wsdl file is invalid because if I try to add
a web reference to that service in VS, it craps out, saying it has
invalid characters. I think it uses unicode characters but has an
invalid xml encoding statement. I just want to know how I can verify
this and how do I access a error message during this process to display
to the end user?

using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Security.Permissions;
using System.Text;
using System.Web.Services;
using System.Web.Services.Description;
using System.Web.Services.Discovery;
using System.Xml;
using System.Xml.Serialization;

namespace WebReferenceTest
class Program
[SecurityPermissionAttribute( SecurityAction.Demand, Unrestricted =
true )]
static void Main( string[] args )
string url = "";
XmlDocument document = new XmlDocument();
document.Load( new StringReader( new WebClient().DownloadString( url
) ) );

// remove Any tags, this causes 400+ validation warnings
XmlNodeList nodes = document.GetElementsByTagName( "xs:any" );
if( nodes != null )
for( int index = 0, count = nodes.Count; index < count; index++ )
nodes[0].ParentNode.RemoveChild( nodes[0] );
string contents = document.OuterXml.Replace( "null", string.Empty );
using( StreamWriter writer = new StreamWriter( "output.wsdl" ) )
writer.Write( contents );

// Create a WSDL collection.
DiscoveryClientDocumentCollection wsdlCollection = new
ServiceDescription description = ServiceDescription.Read( new
StringReader( contents ) );
wsdlCollection.Add( url, description );
// Create a namespace and a unit for compilation.
CodeCompileUnit unit = new CodeCompileUnit();
CodeNamespace space = new CodeNamespace( "eBay.Soap" );
unit.Namespaces.Add( space );

// Create a web referernce using the WSDL collection.
WebReference reference = new WebReference( wsdlCollection, space );
reference.ProtocolName = "Soap12";

// Create a web reference collection.
WebReferenceCollection references = new WebReferenceCollection();
references.Add( reference );

// Compile a proxy client and print out the code.
CodeDomProvider provider = CodeDomProvider.CreateProvider( "CSharp"
WebReferenceOptions options = new WebReferenceOptions();
options.Style = ServiceDescriptionImportStyle.Client;
options.CodeGenerationOptions =
StringCollection results =
provider.GenerateCodeFromCompileUnit( unit, new StreamWriter(
"Output.cs" ), new CodeGeneratorOptions() );

Nov 12 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.