how to Authenticate WCF service globally using custom token - c#

I wanted to add a global Custom token authentication on each service call in wcf rest service.
My service having more than 50 (Get/Post) methods.
Now I am passing token in each method and authenticate them, Now i wanted to do that globally using something like global.asax or routing or attribute reading
Thank you

For getting the dynamic solution i went through multiple links to understand WCF parameter validation and I found the solution here
Create a class that inherate IparameterInspector
IparameterInspector usesbase class as IoperationBehaviour
Add the created class to your operation contract as a Attribute
For detail descrption see the link
WCF Extensibility using IParameterInspector
If you want you can Comment you query or question to get my actual code for Get and Post method

Related

add wss security header via proxy class

I consuming web service by proxy class generated from wsdl file. Main class is inherits from SoapHttpClientProtocol. In description of this web service I have an annotation
"Service invocation context. Implemented in the form ws-security
custom token"
I belive is it means that I need add wss security header and actually, I don't know how to go about it. Can I find aleary method or properties inherited from SoapHttpClientProtocol class to do it? Maybe I should consume this web service without the proxy class?

How to hide some declared Methods in ASMX file in Web Service C#

i have one doubt in Web Service / WCF
i'm creating the service and it's having 10 methods respectively
test1() , Program1(int age),Describe1(), DisplayAge(string name),,SimilarInterest(),ServiceCall(), Hide(), Difference(), WebService() and Help()
now after hosting this service in asmx only the below methods should display. others should not need to display.
DisplayAge(string name),,SimilarInterest(),ServiceCall() only these three should display when i call the http://URL.asmx?wsdl
the other 7 methods should not need to display in asmx wsdl file .how to do that?
As far as I know, in XML Web Service(ASMX), this should not work if you want the service to be both invoked and not shown in the WSDL. Either using private decorated methods or removing the [WebMethod] attribute causes the method to no longer be invoked. If in WCF we can implement authentication, authorization that individual methods cannot be invoked, or simply not expose metadata. But we cannot hide the specified method (but can be called by the outside world).
https://social.msdn.microsoft.com/Forums/en-US/533e0361-e9e0-400b-a7b2-f098a9ef3e75/how-to-prevent-web-method-from-showing-on-service-description-page?forum=asmxandxml
Feel free to let me know if there is anything I can help with.

Configure session in WEB API 2 with OWIN configuration

I have been trying to configure my Web API 2, that uses the Startup class to configure the API (OWIN Self-Hosting), for it to support the use of the Session object.
I am aware that a REST application should be statless, but I need to use the session anyway.
I have tried this solution, but it won't work.
I have also looked at multiple blog posts and articles that suggest using a custom RouteHandler that overrides the GetHttpHandler method to use a controller that implements IRequiresSessionState (as explained here). But my startup class uses HttpRouteCollection, and my method MapHttpRoute does not support the property RouteHandler.
I have tried moving the route configuration from my Startup class to the Application_Start in a Global.asax I have added, but it is not working either (the requests are not reaching the controllers).
Any suggestion would be much appreciated!
Thank you

How can a WCF Service obtain Query Parameters?

I'm working on an Azure service for a Windows Phone app. I need the Azure Service to access the users' OneDrive. Following this article, my scenario should be:
The user sign in to Windows Live on the WP app.
The Live web service sends the authorization code to a redirect URI that I defined, with the code appended as a query parameter named code, as:
http://www.example.com/callback.php?code=2bd12503-7e88-bfe7-c5c7-82274a740ff
I get the authorization code and access the users' data
After investigating a lot in Service, I still can't find a way to capture the query parameter in my web service. As I am new to this area, I don't know where to focus on. I'll be really appreciated if you can give my an advise or answer my following questions:
Can I access the service just using the url with parameter in a browser? How can I see if the service is working properly?
An article mentioned using WCF [Web Get] attribute to get Query Parameters, but I still don't know how to implement both the IService1.cs and Service1.cs file, could you give me a sample about how to access the value of Query Parameter?
Thanks!
I'm not sure if i understand your problem properly but if you want your RESTfull WCF service to be the callback receiver for the request code, your Service must be hosted with a WebHttpBinding and a ServiceContract similar to this one.
[ServiceContract]
public interface IService
{
[WebGet(UriTemplate = "callback?code={requestCode}")]
void OAuthCallback(string requestCode);
}
So if the base address of your Service is "http://service.mydomain.com/MyService.svc" the OAuthCallback Method will be called when a http GET request to "http://service.mydomain.com/MyService.svc/callback?code=RequestCode" is made.

How to expose WCF method?

I'd like to access a WCF method via url. For example:
localhost:8080/TestService.svc/MyMethod
When I do the above, I get a webpage cannot be found. In the Interface file, I have added the following above MyMethod.
[WebGet]
[OperationContract]
void MyMethod();
but that didn't change anything. Any ideas?
How does your web.config look like? Are you using REST?
Have you looked at below post?
Making a WCF Web Service work with GET requests
I don't think you can. You need to use REST to do what you want.
Or use a Controller/Action (if this is MVC) that will create a proxy object to consume the service e.g.
ServiceClient client = new ServiceClient();
client.MyMethod()
Here is a nice example on how to achieve this
I think the quickest solution is to use a factory. It seems likely they would want a restful service so if you follow this guide you wont even need to specify anything in the web.config. See the first answer on this question.
Bare Minimum Configuration for RESTful WCF

Categories

Resources