Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To avoid the confusion of having two different WSDLs available on two different URLs (i.e., the *.asmx?wsdl URL and a custom URL) in your web service application, you could write an HttpModule that intercepts the request to the *.asmx?wsdl URL and returns your custom WSDL instead.</p> <p><strong>EDIT:</strong> Here's an example, adapted and simplified from some code I previously wrote that makes a custom WSDL available at the standard *.asmx?wsdl URL.</p> <pre><code>using System; using System.IO; using System.Web; using System.Web.Services.Configuration; namespace DemoWebService { public class CustomWsdlModule : IHttpModule { public void Init(HttpApplication application) { // hook up to BeginRequest event on application object application.BeginRequest += new EventHandler(this.onApplicationBeginRequest); } public void Dispose() { } private void onApplicationBeginRequest(object source, EventArgs ea) { HttpApplication application = (HttpApplication)source; HttpRequest request = application.Request; HttpResponse response = application.Response; // check if request is for WSDL file if ( request.Url.PathAndQuery.EndsWith(".asmx?wsdl", StringComparison.InvariantCultureIgnoreCase) ) { // if Documentation protocol is not allowed, throw exception if ( (WebServicesSection.Current.EnabledProtocols &amp; WebServiceProtocols.Documentation) == 0 ) { throw new System.InvalidOperationException("Request format is unrecognized."); } // get path to physical .asmx file String asmxPath = request.MapPath(request.Url.AbsolutePath); // build path to .wsdl file; should be same as .asmx file, but with .wsdl extension String wsdlPath = Path.ChangeExtension(asmxPath, ".wsdl"); // check if WSDL file exists if ( File.Exists(wsdlPath) ) { // read WSDL file using ( StreamReader reader = new StreamReader(wsdlPath) ) { string wsdlFileContents = reader.ReadToEnd(); // write WSDL to response and end response without normal processing response.ContentType = "text/xml"; response.Write(wsdlFileContents); response.End(); } } } } } } </code></pre> <p>This simplified code assumes that your custom WSDL is in the same folder as your .asmx file with a .wsdl extension. The HttpModule needs to be hooked into your web service application via the web.config file:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;configuration&gt; &lt;!-- ... --&gt; &lt;system.web&gt; &lt;!-- ... --&gt; &lt;httpModules&gt; &lt;add type="DemoWebService.CustomWsdlModule" name="CustomWsdlModule"/&gt; &lt;!-- ... --&gt; &lt;/httpModules&gt; &lt;!-- ... --&gt; &lt;/system.web&gt; &lt;!-- ... --&gt; &lt;/configuration&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload