Get SvcHost assembly location (path) using SvcImplementation assembly - wcf

I have windows 8.1 x64, Visual Studio 2012 x86, IIS 8.5.
I have Wcf Service Host project (contains svc file)
<%# ServiceHost Language="C#" Debug="true" Service="WcfServiceImplementation.MyService" %>
I have Wcf Service implementation project.
Wcf Service hosted in IIS
I have 2 assemblies: WcfService.Host.dll and WcfServiceImplementation.dll
This code in WcfServiceImplementation.dll:
1)
Assembly.GetEntryAssembly()
gets null.
2)
Assembly.GetExecutingAssembly()
gets WcfServiceImplementation.
3)
Assembly.GetCallingAssembly()
gets System.ServiceModel.
How can I get Service.Host assembly location programatically in the code that execute WcfServiceImplementation assembly?
In general, for any Wcf Service or Web Application, how get the "main assembly" (the wcf service host, the web application) ?
My trace (log):
ProcessName: w3wp
Is64BitOperatingSystem: True
Is64BitProcess: True
SystemConfigurationFile: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config
ConfigurationFile: C:\TFS\Tests\WcfService\web.config
MainModule.FileName: c:\windows\system32\inetsrv\w3wp.exe
MainModule.ModuleName: w3wp.exe
BaseDirectory: C:\TFS\Tests\WcfService\
ApplicationBase: C:\TFS\Tests\WcfService\
FriendlyName: /LM/W3SVC/2/ROOT-5-130404032112324911
ApplicationName: c36153ea
Code in WcfServiceImplementation assembly:
Assembly.GetEntryAssembly():
GetAssemblyExtendedData. Assembly null
Assembly.GetExecutingAssembly():
Location: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2090c609\c36153ea\assembly\dl3\92d3ec19\b0fa1582_c649cf01\WcfServiceImplementation.dll
ProcessorArchitecture: MSIL
Assembly.GetCallingAssembly():
Location: C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll
ProcessorArchitecture: MSIL
Suggestions ?

This one worked for me in WCF service:
AppDomain.CurrentDomain.RelativeSearchPath
For example:
string certFilePath =
AppDomain.CurrentDomain.RelativeSearchPath + "\" +
CERTIFICATES_DIRECTORY_NAME + "\" + CERTIFICATE_FILE_NAME;
You can see the files are copied under sub-directory and these files in the solution are marked as build-action "Copy to output directory" which copies directory as well as files (which I wanted for my case, otherwise use resources as the link in the project).

Related

Deploying WCF Service on Non SharePoint Envirnment

I have a plain .Net based WCF Service which is interacting with SharePoint (2010) Site. I need to deploy it on the Production environment which is not a SharePoint environment. After creating and deploying the solution its giving error
"Could not load file or assembly 'Microsoft.SharePoint.Library, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified "
Please help me with the steps to create a deployment package for NON-SharePoint Environment.
Thanks
Yamini
If you are deploying your WCF on non-Sharepoint environment, You cannot use Sharepoint server object model inside wcf.
You need to use Client object model and add reference to Microsoft.Sharepoint.Client and Microsoft.Sharepoint.Client.Runtime

Error while consuming WCF from class library from an application deployed on IIS 7.5

I am new to WCF services and getting an Error while consuming WCF from Class library, pls correct if i wrong somewhere; I m explaining my problem in steps
1.separate WCF project that is deployed in local IIS, running well from Visual studio(dev env).
2.created CustomClientChannelFactory class and consuming WCF from Business Layer(ie class library)
CustomClientChannelFactory<IPDServices.IIPDServices> objChannelFactory = new CustomClientChannelFactory<IPDServices.IIPDServices>("BasicHttpBinding_IIPDServices", "HISWCFService.config");
IPDServices.IIPDServices obj = objChannelFactory.CreateChannel();
strXML = obj.GetAllAdmittedPatients(strHospitalId);
binding information stored in HISWCFService.config (renamed App.config) and copied in
specified location (C:\Program Files\Common Files\microsoft shared\DevServer\10.0), this is working well on local VS WebDev server while debugging app.
problem started when i deployed App in IIS getting an Error
"The Address property on ChannelFactory.Endpoint was null. The ChannelFactory's Endpoint must have a valid Address specified."
Please suggest

Silverlight 4 WCF Ria Services 404 Error

My Silverlight 4 WCF RIA Services Project works fine on my dev machine from VS 2010 also published, from IIS. But when I deploy it to the client machine (windows7) all my service methods return NotFound error. I tried all blog posts and forums all day long but in vain. service url from fiddler returns on the dev machine but 404 on the client pc. I am so frustrated right now. In my last trial I saw about manual creation of physical .svc file
<%# ServiceHost Service="Fully.Qualified.NameOfYourService" Factory="System.ServiceModel.DomainServices.Hosting.DomainServiceHostFactory" %>
But couldn't figure out how to implement, someone please save my future??
install .NET framework 4.0;
install IIS7 and enable "Windows Communication Foundation HTTP Activation" in the "Windows features";
install WCF RIA Services with the option "SERVER=true" (you could also skip this step setting "Copy Local=True" for the System.ServiceModel.DomainServices.* dlls stored in the bin folder of your web application);
msiexec /i RIAServices.msi SERVER=true
use the "Add Application" menu in "IIS Manager" specifying the application name, the deploy dir containing your app and "ASP.NET v4.0" as application pool;
if you obtain a "404 error" it's also useful to run "aspnet_regiis.exe -i" from the "C:\Windows\Microsoft.NET\Framework\v4.0.30319" directory;
simple, create a new web site [to host your application] and then run the "aspnet_regiis -i" from the framework folder [Framework for 32bit or Framework64 for 64bit applications].
When viewing the HTTP Handlers section under the new website and you will see the various mappings for the .svc files have been created [look back at the default website and these havent been upgraded!]. This then resolved the 404 errors and Fiddler was also confirming that the svc files were being accessed correctly.
As a last configuration make sure the application pool is set to the ASP.NET 4 Integrated mode pool and enable the allow 32bit applications.
Hope this helps :-)

WCF service reference in class library

I added wcf service (exposed by biztalk) proxy and app.config file in VS 2005 class library project and i am calling this class library methods from windows application. In this case getting error while creating service instance, so i moved app.config file from class library to window applcation, now working fine.
Question: If i will change service url from machine001 to machine002 in config file (from bin folder but not from application) and run the app from exe file. Will it work without build.
Class library configuration always depends on configuration file (web.config / app.config) of parent application that is really using it. And Parent application should be a console / winform / ASP.NET application and can be a windows service. Any change in WinForm's app.config will change the behavior of your class library.
To Answer your question, Yes if you change service url from machine001 to machine002 in config file of windows application it will work if machine002 is hosting the WCF service.
Hope it clears your doubt.

Connection string in app.config in a class library

I am creating solution and inside I have three projects:
A WCF Service Library Project
A DataAccess Project (Class Library)
A Web site for hosting WCF service
The implementation of the service is on the project # 1, but in order to access the DataBase I use a second project that implements the data access using a class library project.
That problem is in order to get data access I need to configure a connection string, but that connection string must be configurable in a production environment, I meant in production I am going to deploy the site, which is a very simple project that contains only a reference WCF Service Library Project then a guy from database department will configure the connection string.
In development I have an app.config on the data access project but when I do the release that app.config is embedded on the dll.
Any ideas how can we achieve our purpose
The connection string must be in the application configuration file of the executing assembly. This means that you can provided the configuration file for your assembly along with the assembly itself but anyone who wants to use your assembly must update their configuration file to include the values that your assembly relies on.
The connection string in your app.config (data layer) is not embedded in the dll.
If you look in the app.config file in your data layer project, you will probably have a connectionStrings section. you need to put the connectionStrings in the web.config of your WCF service website.
This can be configured in your production environment.
I had a mistake, I was using a different name on the web.config of the WCF site, I just copy the the exact part of the app.config to the web.config and its working now.
Thanks for your help