467,117 Members | 1,012 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,117 developers. It's quick & easy.

Obtain server path in web services

Hi,

I have a WCF service deployed in IIS. How could I get the physical server
path that the service resides, inside the service code?

--

Thanks.

Daniel
Aug 10 '07 #1
  • viewed: 17578
Share:
6 Replies
On Aug 10, 4:42 am, Daniel <daniel.s...@newsgroup.nospamwrote:
Hi,

I have a WCF service deployed in IIS. How could I get the physical server
path that the service resides, inside the service code?

--

Thanks.

Daniel
I get access to the physical path in my global.asax.cs file in the
Application_Start event using ...

Context.Request.PhysicalApplicationPath

If inside a method, I think you can use...

HttpContext.Current.Request.PhysicalApplicationPat h

Ron

Aug 10 '07 #2
Thanks Ron. I think I have tried this approach, but it seems that
HttpContext.Current is null at my site. I guess this is for ASP.NET web
services only.

Daniel
"ro*************@yahoo.com" wrote:
On Aug 10, 4:42 am, Daniel <daniel.s...@newsgroup.nospamwrote:
Hi,

I have a WCF service deployed in IIS. How could I get the physical server
path that the service resides, inside the service code?

--

Thanks.

Daniel

I get access to the physical path in my global.asax.cs file in the
Application_Start event using ...

Context.Request.PhysicalApplicationPath

If inside a method, I think you can use...

HttpContext.Current.Request.PhysicalApplicationPat h

Ron

Aug 13 '07 #3
Hi Daniel,

Regarding on the question you mentioned, I think the problem here is that
WCF service is unlike ASP.NET web application or webservice which is not
quite coupled with ASP.NET runtime engine and pipeline. That's why we can
not quite use the ASP.NET specific approaches to get the path or virtual
path.

Currently, I've tried the .NET AppDomain based approach to get the running
WCF AppDomain's base directory, and it seems can point to the hosted
application directory's physical root directory path. here is a test code
snippet demonstrate this:

================
public class Service : IService
{
public string SayHello(string name)
{

return "Hello " + name + "\r\n" +
AppDomain.CurrentDomain.BaseDirectory;
}

................
======================

Hope this helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 13 '07 #4
On Aug 12, 8:14 pm, Daniel <daniel.s...@newsgroup.nospamwrote:
Thanks Ron. I think I have tried this approach, but it seems that
HttpContext.Current is null at my site. I guess this is for ASP.NET web
services only.

Daniel

"ronscottlang...@yahoo.com" wrote:
On Aug 10, 4:42 am, Daniel <daniel.s...@newsgroup.nospamwrote:
Hi,
I have a WCF service deployed in IIS. How could I get the physical server
path that the service resides, inside the service code?
--
Thanks.
Daniel
I get access to the physical path in my global.asax.cs file in the
Application_Start event using ...
Context.Request.PhysicalApplicationPath
If inside a method, I think you can use...
HttpContext.Current.Request.PhysicalApplicationPat h
Ron
Yep, correct. Fyi, it is possible to use the ASP.NET values in WCF
services if you are running in ASP.NET Compatibility mode.

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

Because of some limitations with WCF Sessions, I am running in this
mode and have access to the HttpContext values, as well as the Session
and Application variables.

Ron

Aug 13 '07 #5
Thanks for Ron's informative input,

Hi Daniel,

I agree that the "enable aspNetCompatibility" for the WCF host should be a
good solution here.

Also, you can read some additional comments about this setting to see
whether it does fully meet your requirement:

#<serviceHostingEnvironment>
http://msdn2.microsoft.com/en-us/library/ms731336.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Aug 14 '07 #6
Hi Daniel,

Have you got progress on this or does our suggestion help you on this
issue? If there is anything else we can help, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Aug 16 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Tony Wright | last post: by
reply views Thread by Henrique Berenguel | last post: by
8 posts views Thread by Woody Splawn | last post: by
8 posts views Thread by bryan@newsgroups.nospam | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.