0
我正在開發VS2008中的wcf應用程序。我想將該WCF服務作爲窗口服務託管。但我也想將該服務公開爲.asmx(web服務)。將WCF服務公開爲asmx(網絡服務)並託管在窗口服務
可以嗎?有什麼方法可以將.asmx(web服務)公開爲wcf服務,但需要在窗口服務中進行託管。
我正在開發VS2008中的wcf應用程序。我想將該WCF服務作爲窗口服務託管。但我也想將該服務公開爲.asmx(web服務)。將WCF服務公開爲asmx(網絡服務)並託管在窗口服務
可以嗎?有什麼方法可以將.asmx(web服務)公開爲wcf服務,但需要在窗口服務中進行託管。
當作爲Windows服務託管,您可以爲您服務的基地址設置爲你想要的任何URL,例如:
(假設你已經有一個名爲「yourServiceClass」實現服務合同類)
public class ExampleWindowsService : ServiceBase
{
public ServiceHost host = null;
public static void Main()
{
ServiceBase.Run(new ExampleWindowsService());
}
protected override void OnStart(string[] args)
{
if (host != null)
{
host.Close();
}
Uri baseAddress = new Uri("http://localhost:80/yourservice.asmx");
host = new ServiceHost(typeof(yourServiceClass), baseAddress);
host.Open();
Console.WriteLine("Service hosted ...");
}
}
然後,您可以通過編程或配置文件添加所需的端點和行爲。查看here以查找有關如何將WCF服務實現爲Windows服務的更多信息。
你是什麼意思,暴露爲asmx?文件擴展名應該沒有關係。 –
我認爲他的意思是與你對asmx服務期望的綁定和行爲相同。 –
@BuhBuh:今天早上我讀頭腦太早了。 –