我正在开发一个处理图片上传的Asp.Net网络服务,比如名为“Upload.asmx”:
核心代码:
[WebMethod]
public void upload(){
//handler the image stream ,save them .
String identify = saveImage(...);
//generate the image url
String theURLOfThisWebService;
Response.Write(theURLOfThisWebService + "/image?identify="+identify);
...
}
[WebMethod]
public void image(String identify){
//retrieve image from database
}
如图所示,我必须得到theURLOfThisWebService
,但是一旦部署到不同的位置,这个网址就会有所不同。
例如,可以像
一样调用它http://server/upload.asmx/upload ==> I need http://server/upload.asmx
http://anotherserver/service/upload.asmx/upload ==> I need http://anotherserver/service/upload.asmx
即使我可以通过:
String url = Request.RawUrl;
String theURLOfThisWebService = url.substring(0,url.IndexOf('.asmx')+5);
但我想知道是否有官方方法?