JedNebula
asked on
Using Properties with a WCF Service
Having never touched WCF before, I am having a play now.
The first thing I wanted to do, was restrict people from using certain methods until after they had successfully authenticated.
For testing purposes, I added a class level boolean property which I set to true inside an Authenticate method. My theory was that I could then simple check that variable in each method they called to see if I needed to throw them out, or allow them to continue on.
What I found though, was that, even though one method would set the property to True, the next method would read it's value as False again.
This led me to wonder if you can even use properties in WCF services, or do they go out of scope after each method call?
I found a couple of articles, which thankfully assured me that I wasn't the first person to wonder this, but even following their code tweaks, I couldn't get a class level variable to 'stick'.
http://tech.pro/tutorial/908/wcf-tip-using-properties-in-service-contracts
http://visualstudiomagazine.com/blogs/tool-tracker/2012/11/using-properties-in-wcf-services.aspx
Am I going about this wrong way?
The first thing I wanted to do, was restrict people from using certain methods until after they had successfully authenticated.
For testing purposes, I added a class level boolean property which I set to true inside an Authenticate method. My theory was that I could then simple check that variable in each method they called to see if I needed to throw them out, or allow them to continue on.
What I found though, was that, even though one method would set the property to True, the next method would read it's value as False again.
This led me to wonder if you can even use properties in WCF services, or do they go out of scope after each method call?
I found a couple of articles, which thankfully assured me that I wasn't the first person to wonder this, but even following their code tweaks, I couldn't get a class level variable to 'stick'.
http://tech.pro/tutorial/908/wcf-tip-using-properties-in-service-contracts
http://visualstudiomagazine.com/blogs/tool-tracker/2012/11/using-properties-in-wcf-services.aspx
Am I going about this wrong way?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Add this code to your web.config
<!-- This is existing in your code -->
<system.serviceModel>
<!-- Add this from here -->
<services>
<!-- change the name and contract to your needs -->
<service name="Service">
<endpoint binding="wsHttpBinding" contract="IService">endpoint>
service>
<services>
<!-- End add -->
ASKER
Ok thanks.
It compiles okay, but it has the following 2 warnings.
I also can't get the service to add to the client add. It's still trying to use Basic HTTP for some reason.
27-11-2014-12-57-07-PM.jpg
27-11-2014-01-01-02-PM.jpg
It compiles okay, but it has the following 2 warnings.
I also can't get the service to add to the client add. It's still trying to use Basic HTTP for some reason.
27-11-2014-12-57-07-PM.jpg
27-11-2014-01-01-02-PM.jpg
You can try to add this to the ServiceModel tag.
and change the following
<protocolMapping>
<add scheme="http" binding="wsHttpBinding"/>
</protocolMapping>
and change the following
<endpoint binding="wsHttpBinding" contract="IService">endpoint>
to
<endpoint binding="wsHttpBinding" contract="IEskimoAPISevice">endpoint>
ASKER
No I'm afraid that made no difference.
Would someone be able to put together a sample app, which they can zip and post?
Hopefully I was clear enough in the original question as to what I am trying to achieve.
If this is possible at all, I'll be able to compare the project with mine and hopefully see where I am going wrong.
Would someone be able to put together a sample app, which they can zip and post?
Hopefully I was clear enough in the original question as to what I am trying to achieve.
If this is possible at all, I'll be able to compare the project with mine and hopefully see where I am going wrong.
ASKER
In the end, I managed to get it working by downloading the code found here:
http://www.codeproject.com/Articles/127395/Implementing-a-WCF-Service-with-Entity-Framework
I copied the <system.serviceModel> section from his app.config into my Web.config and changed the relevant names.
All okay now - working with Sessions :-)
I could even take off the
SessionMode:=SessionMode.R equired
attribute and it still worked.
http://www.codeproject.com/Articles/127395/Implementing-a-WCF-Service-with-Entity-Framework
I copied the <system.serviceModel> section from his app.config into my Web.config and changed the relevant names.
All okay now - working with Sessions :-)
I could even take off the
SessionMode:=SessionMode.R
attribute and it still worked.
ASKER
Thank you for your reply.
I have changed my Interface Decoration to:
Open in new window
but unfortunatey, I now receive the following error when trying to update the Service Reference in my client app:
I'm not too sure how to change the Binding to not use BasicHttp to be honest. Is it done in the client App.Config, or in the Server project somewhere? The server project only has a web.config as I am also running a Web API project alongside. Here is the content:
Open in new window