WCF Interview Questions and Answers Part 8

1. What happens when we use same name for two methods in interface in wcf?
Ans. No compilation error occurrs but it will give runtime error.

Here what WSDL comes into picture. When you start WCF Service it uses Metadata of operation contact to create WSDL but WSDL is a open source message communication standard and does not support Object Oriented Programming concepts like Inheritance and Overloading.

So to make metadata of WCF service unique we have to use Name property of operation contract to make methods name in unique in WSDL. Following a code for that.

[ServiceContract]
    public interface ITestService
    {
        [OperationContract(Name = "TestMethod")]
        string TestMethod();

        [OperationContract(Name = "TestMethod with name")]
        string TestMethod(string name);

    }


2. Can we access SOAP based web service directly from web browser?
Ans. No we cannot. Because it requires form post.

3. To create new endpoint wheat need to be changed in webconfig file?
Ans. Address + Binding + Contract = Endpoint
  It means these three things have to be changed to add new endpoint.



4. How do we provide addresses to multiple endpoints in webconfig file?
Ans. Generally, we pass relative address in endpoints by defining the base address in host tag.

Example:

 <services>
      <service name="DemoService.TestService">
<endpoint address="/myfirstbinding" binding="wsHttpBinding" bindingConfiguration="firstBinding"

contract="DemoService.ITestService">         
        </endpoint>
        <endpoint address="/mysecondbinding" binding="webHttpBinding" bindingConfiguration="secondBinding"

contract="DemoService.ITestService">         
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/TestService.svc"/>
          </baseAddresses>
        </host>
 </service>
</services>



5. Where do we set address filter mode in wcf?
Ans. Generally on serviceBehavior we keep filters.

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]



6. Can we pass other data type variables as parameters to operations using "UriTemplate" in wcf?
Ans. The type of variables for UriTemplate path segments is limited to type 'string'. For other types you can move parameters to query part like this,

[OperationContract]
[WebGet(UriTemplate = "TestMethod/?sid={sid}")]
TestMethod(Int32 sid);

 






Subscribe

Receive Quality Tutorials Straight in your Inbox by submitting your Email below:

Delivered by FeedBurner

Protected by Copyscape Duplicate Content Checker