I have 2 question related to the web services.
This is a very common interview question as well: Is it possible to overload a web method in a web service? The answer is yes, you need to use MessageName property for this.
In Java, two or more methods may have the same name if they differ in parameters (different number of parameters, different types of parameters, or both). These methods are called overloaded methods and this feature is called method overloading. For example: void func() { ... }
Overloading Methods Method overloading can be achieved by the following: By changing the number of parameters in a method. By changing the order of parameters in a method. By using different data types for parameters.
So clearly by default WCF does not allow you to overload methods in service. However there is one attribute in OperationContract which can allow you to overload method at service end.
How we achieve the method overloading in web services.
If you are using SOAP you can't. Method names must have unique names in the exported WSDL. Depending on the technology you are using there are different ways to specify a method name. For example in WCF you could use the [OperationContract]
attribute to specify a name:
[ServiceContract]
public interface IMyService
{
[OperationContract(Name = "Foo")]
void Foo();
[OperationContract(Name = "FooWithId")]
void Foo(int id);
}
How to implement security(authentication) in web services.
The following guide is a very good start for implementing security in WCF.
Okay for overloading:
[WebMethod(MessageName = "MaxInt", Description = "Compare two int values
and return the max value", EnableSession = true)]
public int MaxValue(int a, int b)
{
return (a > b ? a : b);
}
[WebMethod(MessageName = "MaxFloat", Description = "Compare two float values
and return the max value", EnableSession = true)]
public float MaxValue(float a, float b)
{
return (a > b ? a : b);
}
What do you mean precisely by authentication? You can obviously use a validation key to access webservice. The question is confusing. Elaborate please.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With