?
Solved

Consuming WCF Service in Class Library

Posted on 2011-04-26
3
Medium Priority
?
808 Views
Last Modified: 2013-11-15
Hello All
I have written a WCF service and hosted it on IIS 7.
I am trying to consume it through a c# class library project.
I tried both SVCUtil.exe and 'Add Service Reference' option in VS 2010. But I cannot seem to access the operation in the service.
I get an 'Object Reference' error.

i know for sure the Service works fine because I ran it in Debug Mode in visual studio, and used the test client.

I read in a blog that class library projects cannot read a config file.
So I use a custom channel factory class to read the .config file for the endpoint and binding.
Its through this channel that i try to access the service operation, and thats where I get the error.

Not getting why..

Please help!
Thanks in advance.
namespace Test
{
    public class Class1 : ProjectEventReceiver
    {
        public override void OnCheckIn(PSLib.PSContextInfo contextInfo, ProjectPostEventArgs e)
        {          
            StartService(e.ProjectGuid);
        }

        public void StartService(Guid projectUID)
        {
            try
            {
                CustomChannelFactory<ServiceReference1.IService1> channel = new CustomChannelFactory<ServiceReference1.IService1>("WSHttpBinding_IService1", "C:\\Users\\Administrator\\Documents\\Visual Studio 2010\\Projects\\Test\\Test\\app.config");

                ServiceReference1.IService1 svc = channel.CreateChannel();

                svc.CommenceSubstitution(projectUID);
                channel.Close();
            }
            catch (Exception ex)
            {

            }
        }
    }
}

Open in new window

0
Comment
Question by:suchitrashetty
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
Craig Wagner earned 1500 total points
ID: 35475192
What you read about class libraries and config files is not entirely correct. In Visual Studio each project gets its own config file. However, the config file for a class library is not deployed automatically at run-time, and even if you manually copy it to your application folder it won't be read. The only config file that is used by a running application is the config file for the application's main entry point. If it is a web application that means web.config, if it is any other type of application that means <appname>.exe.config.

You could try taking all of the endpoint and binding configuration information that was generated in your class library's config file when you set the reference and copy it to the hosting application's configuration file.
0
 

Author Comment

by:suchitrashetty
ID: 35506666
Thanks andsSorry for the late response.

That is how i would do it with any application. But in this case, the class library I am developing is an Event Handler to be registered on the Project Server 2010, specifically Project Web Access (PWA). I am new to PWA and Sharepoint customization. Would you know where the config file would be in this case?
0
 

Author Closing Comment

by:suchitrashetty
ID: 35880694
The solution was not pertinent to my situation.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question