I have written a WCF REST Service as follows
namespace UserService
{
// TODO: Modify the service behavior settings (instancing, concurrency etc) based on the service's requirements. Use ConcurrencyMode.Multiple if your service implementation
// is thread-safe.
// TODO: Please set IncludeExceptionDetailInFaults to false in production environments
[ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceContract]
public class Service
{
UserManager userManager = new UserManager();
[OperationContract]
[WebGet(UriTemplate = "{userName}")]
[WebHelp(Comment = "Gets an user object given the username")]
public User GetUser(string userName)
{
return userManager.Read(userName);
}
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "", RequestFormat=WebMessageFormat.Xml, ResponseFormat=WebMessageFormat.Xml, BodyStyle=WebMessageBodyStyle.Bare)]
[WebHelp(Comment = "Creates an User")]
public void CreateUser(User user)
{
userManager.Create(user);
}
}
}
I am accessing this from my ASP.NET application as follows.
HttpClient client = new HttpClient();
HttpContent content = null;
DiscussionForum.Library.User user = new User();
user.UserEmailAddress = emailAddressTextBox.Text;
user.UserName = userNameTextBox.Text;
user.UserPassword = passwordTextBox.Text;
content = HttpContentExtensions.CreateXmlSerializable<DiscussionForum.Library.User>(user);
content.LoadIntoBuffer();
HttpResponseMessage response = client.Post(new Uri("http://localhost/UserService/Service.svc"),"application/xml", content);
Response.Write(response.StatusCode.ToString());
I am getting a Badrequest 400 in the status code on the client side.
Am I missing something?