iki farklı URL geçerli iki farklı WSDLs sahip karışıklığı önlemek için (yani * .Asmx wsdl URL ve özel bir URL?) Içinde Web servis uygulamasında, isteğinizi * .asmx? wsdl URL'sine engelleyen ve yerine özel WSDL değerini döndüren bir HttpModule yazabilirsiniz.
DÜZENLEME:? İşte adapte ve daha önce standart * .Asmx wsdl URL'de özel bir WSDL kullanılabilir hale getirir yazdığı bazı koddan basitleştirilmiş bir örnek.
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 & 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();
}
}
}
}
}
}
Bu basitleştirilmiş kod özel WSDL bir .wsdl uzantısıyla .Asmx dosyası ile aynı klasörde olduğunu varsayar. HttpModule'in web hizmeti uygulamasına web.config dosyası üzerinden bağlanması gerekir:
<?xml version="1.0"?>
<configuration>
<!-- ... -->
<system.web>
<!-- ... -->
<httpModules>
<add
type="DemoWebService.CustomWsdlModule"
name="CustomWsdlModule"/>
<!-- ... -->
</httpModules>
<!-- ... -->
</system.web>
<!-- ... -->
</configuration>
Bunu neden yapmanız gerekiyor? Aynı değilse, iki eşdeğer değil mi? –
wsdl, arayan tarafından yapılmış ve yaptığım hizmet tam olarak aynı görünmüyor. Ben arayanların isteğini yerine getirdiğinden emin olmak için bunu yapmam. Artık "Sunucu, HTTP Üstbilgisi SOAPAction değerini tanımıyor" hatası alıyorlar. Bu hatayı ayıklarken, olası her hatayı tarafımdan kaldırmak istiyorum. –
İşte çoğul bir eski gönderiden "ASP.NET Web Hizmetlerinde Özel bir WSDL Dosyası Kullanma" deneyeceğim: http: //www.pluralsight.com/community/blogs/craig/archive/2005/12/15/17482.aspx –