我有一個C#web服務,因爲這樣的:如何在C#中獲得webservice自己的端點?
namespace MyProject
{
#region "Frontend"
[WebService(Name="MyWebservice")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class MyWsClass : System.Web.Services.WebService
{
private static readonly IRegisterer reg = new SelfRegisterInDatabase();
private MyWsClass()
{
// tell who I am to a database
MyWsClass.reg.SelfRegister();
}
// A service I expose to the users
[WebMethod]
public object MyMethod(object in)
{
// do some work
return new Object();
}
}
#endregion
#region "Backend"
public interface IRegisterer
{
public void SelfRegister();
}
// Herein lies my question:
public class SelfRegisterInDatabase : IRegisterer
{
private static volatile bool IsRegistered = false;
public void SelfRegister()
{
if(!IsRegistered)
{
// Expecting something like: "http://THEHOST:THEPORT/MyWebservice.aspx?WSDL"
// In principle, the variable part is "THEHOST:THEPORT".
string EndpointUrl =
"HOW_DO_I_GET_WEBSERVICE_ENDPOINT_URL_HERE???"
;
// 1) open a Database connection;
// 2) insert new entry for this EndpointUrl string if doesn't exist;
// 3) and close DB connection
SelfRegisterInDatabase.IsRegistered = true;
}
return;
}
}
#endregion
}
我想知道我怎麼能動態讀取Web服務本身的端點,這樣我可以把它在一個數據庫(註冊比如說,SQL服務器 - 實際INSERT
ing不是我在這裏問的)。我應該使用哪種方法/配置?
一對夫婦的愚蠢的問題,爲澄清:1)讀取參數只能從[WebService的調用時],因此當從WebService類外部調用時,它不起作用(例如)。它是否正確? 2)如果它應該從[WebService]類中調用,它是僅限於[WebMethod]還是可以在[WebService]類構造函數中調用? – jbatista