0

Starting with a .NET webservice developed in Visual Studio 2010 Express, how can I have the own webservice knowing the URL of the WSDL it serves itself?

For example, if I have some boilerplate code

[WebService]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class MyWS : System.Web.Services.WebService
{
  [WebMethod(Description="Something like: http://localhost:12345/MyWS.asmx?WSDL")]
  public int RegisterInDB(string ConnectionString)
  {
    string urlWSDL = "HOW_TO_GET_WEBSERVICE'S_OWN_WSDL_URL_HERE ???";
    int NewRowId;
    // 1) Connect to DB with ConnectionString
    // 2) INSERT into table some info, including urlWSDL
    // 3) Get Id of INSERT'ed row.
    return NewRowId;
  }
}

which method/property gives the WSDL on runtime?

jbatista
  • 2,747
  • 8
  • 30
  • 48
  • 1
    does Consumer not need to know the WSDL to be able to call WSDL() method? – L.B Nov 22 '12 at 16:12
  • Correct. But this has specifically to do with the intention of having the webservice self-register into a database; more to the point: one of the actions of the webservice is to connect to a SQLServer and insert into the DB some information, one of which includes the webserver's own WSDL URL. – jbatista Nov 22 '12 at 16:17
  • 1
    Maybe this link can help. http://stackoverflow.com/questions/11549498/creating-and-exposing-a-soap-service-and-its-wsdl-dynamically-in-c-sharp-with-a – L.B Nov 22 '12 at 16:40
  • Thanks for the suggestion, L.B.. While getting the WSDL will likely find some use in the future, what I'm looking for with this question is instead how to get the dynamic address of the service being served. The whole part before ?WSDL can vary upon deployment, so that's what I'm trying to find (servername, port, path). – jbatista Nov 22 '12 at 16:58
  • Were you aware that the ASMX technology you used for your service is a legacy technology that should not be used for new development? – John Saunders Nov 22 '12 at 17:58
  • Also, I suggest that this is not something that the service itself should do; rather, create an installer program that does it. The WSDL and any included or imported schemas can be retrieved from http://serviceUrl/service.asmx?WSDL – John Saunders Nov 22 '12 at 17:59

0 Answers0