Hi,
I want to retrieve the full WSDL file content, i.e. the XML content preferably as a string. The input will be the URL of the WSDL. If anyone has got any idea then please do reply.
-
Thanks
Ambar
Hi,
I want to retrieve the full WSDL file content, i.e. the XML content preferably as a string. The input will be the URL of the WSDL. If anyone has got any idea then please do reply.
-
Thanks
Ambar
’s WebClient trick is a perfectly fine quick way to grab the top‑level XML, and it answers the original ask from . Two important things that come up after that: many WSDLs are split into multiple documents (wsdl:import / xsd:import), and some services expose metadata only via a MEX endpoint or require authentication — so a single HTTP GET of the .asmx URL doesn’t always give you the “complete” definition. (w3.org)
If you want the full, usable metadata (WSDL + any imported XSDs) prefer a metadata-aware approach. For WCF services use the MetadataExchangeClient which will download the metadata and (by default) resolve imports for you; WsdlImporter can then give you ServiceEndpoint/contract info. If there is no MEX endpoint, fetch the initial WSDL, parse its wsdl:import and xsd:import locations and retrieve those references (resolve relative URIs) before you parse for operation/message parts. See the MetadataExchangeClient guidance. (learn.microsoft.com)
Quick example (WCF):
using System.ServiceModel;
using System.ServiceModel.Description;
var mexAddress = new EndpointAddress(wsdlUrl);
var mexClient = new MetadataExchangeClient(mexAddress) { ResolveMetadataReferences = true };
MetadataSet meta = mexClient.GetMetadata();
var importer = new WsdlImporter(meta);
var endpoints = importer.ImportAllEndpoints(); That gives you resolved metadata you can inspect or save. (learn.microsoft.com)
If you only need to inspect a WSDL and pull operation/parameter names locally, the framework includes ServiceDescription (System.Web.Services.Description) which can read a WSDL stream and expose PortTypes, Operations, Messages and Message.Parts for parameter names — good for the “search for a function name, then get its parameter names” flow mentioned by . If you fetch HTML instead of XML, check you appended ?wsdl (case‑insensitive), watch for redirects/401s, inspect the Content-Type header, and supply credentials or TLS settings if the endpoint requires them. (learn.microsoft.com)
References: WS‑MetadataExchange spec (why ?wsdl / MEX matter), Using MetadataExchangeClient, and the WCF “Retrieve Metadata” sample. (w3.org)
Jump to Post— thines01 401I don't know why you'd do this, but here is a method to read an entire WSDL document into a string:
using System.IO; using System.Net; namespace GetWsdlAsString { class CGetWsdlAsString { static void Main(string[] args) { WebClient wc = new WebClient(); StreamReader fileIn = new StreamReader( wc.OpenRead("
I don't know why you'd do this, but here is a method to read an entire WSDL document into a string:
using System.IO;
using System.Net;
namespace GetWsdlAsString
{
class CGetWsdlAsString
{
static void Main(string[] args)
{
WebClient wc = new WebClient();
StreamReader fileIn = new StreamReader(
wc.OpenRead(""));
string strWsdlData = fileIn.ReadToEnd();
fileIn.Close();
}
}
} Thanks a lot. It's working like a charm.
I don't know why you'd do this, but here is a method to read an entire WSDL document into a string:
I will tell you why. I have a WSDL url (as you already know), a webserivce url, one function name of the webservice which is being called by some app. So I am searching for the particular function name in the wsdl and then getting the parameter names. I don't know if there is any other easier ways to do it.
Thanks again. :)
-
Ambar
It doesn't retrieve the wsdl itself it just retrieve the xxx.asmx....why? and how can I retrieve the wsdl content iteself?
Why don't you just add the wsdl as a web reference to your project? This way it will automatically create all the necessary code so you can access any method in that web service.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.