473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

WebReference and ServiceDescriptionImporter failing to generate code

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

http://msdn2.microsoft.com/en-us/lib...ce(VS.80).aspx

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,
nothing!!!

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 = "https://api.ebay.com/wsapi?wsdl";
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
DiscoveryClientDocumentCollection();
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 =
CodeGenerationOptions.GenerateNewAsync;
StringCollection results =
ServiceDescriptionImporter.GenerateWebReferences(
references,
provider,
unit,
options
);
provider.GenerateCodeFromCompileUnit( unit, new StreamWriter(
"Output.cs" ), new CodeGeneratorOptions() );
}
}
}

Nov 12 '06 #1
0 2490

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Søren Reinke | last post by:
Hi there I have 1 solution (visual studio 2005) within this solution i have many projects, they should all be able to have the same webreference to a webservice. But as far as i can figure...
0
by: jeggert | last post by:
Trying to use the ServiceDescriptionImporter class for generating a proxy on the fly which I understand does essentially the same thing as wsdl.exe or Add Web Reference. There is a property, named...
4
by: Jason P | last post by:
Basically we have a web method with a dynamic URL. The client is developed in C++ and I've been using the webReference.SetUrl( "http://test.example.com..." ) method successfully with various web...
18
by: Scott David Daniels | last post by:
There has been a bit of discussion about a way of providing test cases in a test suite that _should_ work but don't. One of the rules has been the test suite should be runnable and silent at every...
5
by: Kimba | last post by:
Hi. Using VStudio I have developed a WebService which I placed onto several servers. However my application can only access one on server. During runtime, I tried to change the URL of the...
1
by: Ben | last post by:
Hello! im using sharepoint witha thirdparty app which uses a integrated C# code editor and im trying to call a web service using that code editor unfortunatly it appears that a web reference...
0
by: daniel.westerberg | last post by:
Sorry for the swedish error message but that's the server.. anyway quick translation Parsing error message: failed to generate temporary class (result=1). error CS2001: File not found...
1
by: Sagar | last post by:
Hi, I am working on enhancing an aspx page. The server-side is written with inline code. The coding is not in VS. The task is to make calls a webservice...
55
by: lovecreatesbea... | last post by:
Do you check all error conditions for all library calls in you code? Is it necessary to check all errors? Is it convenient to check all errors (or how to make code clean and readable with mass of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.