Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Tuesday, March 25, 2014

DataContract vs Serializable WCF

When applied to a class Serializable attribute serializes everything inside of it including private fields thus the developer has no control as what to expose.

When DataContract attribute is applied to a class it will serialize only the elements decorated with DataMember attribute thus the developer will have more control.

ServiceContract Name property WCF

This property can give your contract a name which is different from the actual interface name. So this way if you decide to change the interface name of a already running WCF service your client wont break.

Ex:

 [ServiceContract(Name="IGoodbyeService")]

    public interface IHelloService

    {

        [OperationContract]

        string GetMessage(string name);

    }


Now the contract name would be IGoodbyeService rather than  IHelloService.

To verify in the WSDL generated check the porttype property it should be IGoodbyeService

Note: Same can be done for OperationContract as well 

Monday, March 24, 2014

Basic Elements of WCF Appconfig

All config items should be inside ,

<system.serviceModel>

This is the WCF namespace provided by Microsoft.

Inside the <system.serviceModel> element you have the <services> element. This is where you configure all your services.
For each service you have a <service> element inside <services> element.
A particular service can be exposed using more than one endpoint. (Ex: http , net.tcp etc)
So for each endpoint in a service you configure a <endpoint> element.
An endpoint element will have three essential things,

  1. address
  2. binding
  3. contract  
Here is a  sample config (not complete) to get an idea.

The service name is HelloService (class and namespace both are HelloService) and has two endpoints (http and net.tcp) for the service.


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="HelloService.HelloService">
        <endpoint address="HelloService" binding="basicHttpBinding" contract="HelloService.IHelloService">
        </endpoint>
        <endpoint address="HelloService" binding="netTcpBinding" contract="HelloService.IHelloService">
        </endpoint>
      </service>
    </services>
  </system.serviceModel>
</configuration>

Tuesday, December 17, 2013

An unsecured or incorrectly fault error WCF

I encountered this error while executing the following snippet,

factory.CreateChannel().Issue(rst)       // Here the rst is a RequestSecurityToken object and 
                                                          //  factory is a WSTrustChannelFactory object

It seems that this was due to incorrect clock skew between my machine (client) and the server (where the WCF service was running). After correcting the time of my machine the error went away.