0

In vs2008 (C#):

I have :

  1. a main project (windows app)
  2. WCF Library
  3. WCF Host
  4. WCF Client (Windows app)

For testing my service with created client, I call my client form in my main proj and after getting the input requirement of service by this form, I start making response of service by calling my service contract method .

In this service I need to create a proper connection string with received parameter for request and I need my application startup path (D:\myProj.dll) to get access to an exe file. Unfortunately after using different kinds of codes that return this path, exactly at point of calling my service, I get another paths I don't need (myproj, bin\debug or c:\programfiles\visual studio9\common7\IDE)

Can you help me ?

For additional info I have to say that I added this path by a command to post-build event of my service library and client.

Please help me to get access to this path (startup path of my project -> D:\myProj.dll)

Thank you in advance

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Shima.Y
  • 373
  • 4
  • 9
  • 18
  • So you want to get the *client's* startup path in the *service* implementation - correct? That won't work - not EVER. Client and service **only** share a transport wire (a network) and a **service contract** - nothing else. The service **CANNOT** "reach back" to the client to get something. The only thing you could do is have a parameter on your service call which your **caller** fills with its startup path before making the call to the service. – marc_s May 21 '12 at 20:55
  • agreed, based on your question it's unclear whose path you're trying to get. Additionally, the execution context matters - if you run from within VS your path will be different than if you launch from the shell, or are running from within IIS or a WCF host. – Jason May 21 '12 at 20:58

1 Answers1

1

from MSDN

path = System.IO.Path.GetDirectoryName(
          System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

to get the path of a DLL your code is using:

string fullPath = System.Reflection.Assembly.GetAssembly(typeof(MyClass)).Location;
Jason
  • 86,222
  • 15
  • 131
  • 146
  • this statement returns bin/debug which is not where my application is running from.actually my application is running from d:myProj.dll . how can I get running path of my host application (my host is a windows service , if it helps!)? – Shima.Y May 22 '12 at 04:20
  • are you running this from within the VS IDE? – Jason May 22 '12 at 14:23
  • no I'm just running from myproj.dll ! and I wanna exactly this path. – Shima.Y May 22 '12 at 15:58
  • Look at my edit above to see how to get the path to a specific dll used by a program. – Jason May 22 '12 at 17:18