You are developing an application to update a users social status. You need to consume the service using Windows Communication Foundation (WCF).
The client configuration is as follow.
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name=”SocialConfig”>
<security mode=”TransportCredentialOnly”>
<transport clientCredentialType=”Basic” realm=”Social API” />
</security>
</binding>
</webHttpBinding>
</bindings>
<client>
<endpoint address=”http://contoso.com” binding=”webHttpBinding”
bindingConfiguration=”SocialConfig”
contract=”ISocialStatus” name=”SocialClient” />
</client>
</system.serviceModel>
The service contract is defined as follows.
[ServiceContract]
public interface ISocialStatus
{
[OperationContract]
[WebInvoke(UriTemplate = “/statuses/update.xml?status={text}”)]
void UpdateStatus(string text);
}
Which code segment should you use to update the social status?
A.
using (WebChannelFactory<ISocialStatus> factory = new WebChannelFactory<ISocialStatus>(“SocialClient”))
{
factory.Credentials.UserName.UserName = user.Name;
factory.Credentials.UserName.Password = user.Password;
ISocialStatus socialChannel = factory.CreateChannel();
socialChannel.UpdateStatus(newStatus);
}
B.
using (ChannelFactory<ISocialStatus> factory = new WebChannelFactory<ISocialStatus>(typeof(ISocialStatus)))
{
factory.Credentials.UserName.UserName = user.Name;
factory.Credentials.UserName.Password = user.Password;
ISocialStatus socialChannel = factory.CreateChannel();
socialChannel.UpdateStatus(newStatus);
}
C.
using (ChannelFactory<ISocialStatus> factory = new ChannelFactory<ISocialStatus>(“POST”))
{
factory.Credentials.Windows.ClientCredential.UserName = user.Name;
factory.Credentials.Windows.ClientCredential.SecurePassword.SetAt(0, Convert.ToChar(user.Password));
ISocialStatus socialChannel = factory.CreateChannel();
socialChannel.UpdateStatus(newStatus);
}
D.
using (WebChannelFactory<ISocialStatus> factory = new WebChannelFactory<ISocialStatus>(typeof(ISocialClient)))
{
factory.Credentials.Windows.ClientCredential.UserName = user.Name;
factory.Credentials.Windows.ClientCredential.SecurePassword.SetAt(0, Convert.ToChar(user.Password));
ISocialStatus socialChannel = factory.CreateChannel();
socialChannel.UpdateStatus(newStatus);
}
Explanation:
WebChannelFactory<TChannel>() Class
(http://msdn.microsoft.com/en-us/library/bb908674.aspx)ChannelFactory<TChannel> Class
(http://msdn.microsoft.com/en-us/library/ms576132.aspx)WebChannelFactory<TChannel>() Initializes a new instance of the WebChannelFactory<TChannel> class.
WebChannelFactory<TChannel>(Binding) Initializes a new instance of the WebChannelFactory<TChannel> class.
WebChannelFactory<TChannel>(ServiceEndpoint) Initializes a new instance of the WebChannelFactory<TChannel> class.
WebChannelFactory<TChannel>(String) Initializes a new instance of the WebChannelFactory<TChannel> class.
WebChannelFactory<TChannel>(Type) Initializes a new instance of the WebChannelFactory<TChannel> class.
WebChannelFactory<TChannel>(Uri) Initializes a new instance of the WebChannelFactory<TChannel> class with the specified Uri.
WebChannelFactory<TChannel>(Binding, Uri) Initializes a new instance of the WebChannelFactory<TChannel> class with the specified binding and Uri.
WebChannelFactory<TChannel>(String, Uri) Initializes a new instance of the WebChannelFactory<TChannel> class with the specified endpoint configuration and Uri.
A