我有一个WCF服务,我正在尝试使用基于浏览器的休息客户端对它进行POST。
如果我在身体中没有传递任何东西,但是如果我向它添加一个json,它就会命中“400 Bad request”。请建议
错误
合同
[OperationContract]
[WebInvoke(Method="POST", BodyStyle=WebMessageBodyStyle.WrappedRequest, UriTemplate="AddEmployee", RequestFormat=WebMessageFormat.Json, ResponseFormat=WebMessageFormat.Json)]
string AddEmployee(Employee emp);
“配置”
<system.serviceModel>
<services>
<service name="GLOpenSourceService.GLOpenSourceService">
<endpoint address="" behaviorConfiguration="restfulBehavior"
binding="webHttpBinding" bindingConfiguration="" contract="GLOpenSourceService.IGLOpenSourceService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/GLOpenSourceService" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
员工模型类
public partial class Employee
{
public int EmployeeID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Nullable<int> DepartmentID { get; set; }
public Nullable<int> Salary { get; set; }
public Nullable<System.DateTime> JoiningDate { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public Nullable<System.DateTime> LastLogin { get; set; }
public Nullable<bool> IsActive { get; set; }
public virtual Department Department { get; set; }
}
系
public partial class Department
{
public Department()
{
this.Employees = new HashSet<Employee>();
}
public int DepartmentID { get; set; }
public string DepartmentName { get; set; }
public Nullable<int> DepartmentHead { get; set; }
public Nullable<bool> IsActive { get; set; }
public virtual ICollection<Employee> Employees { get; set; }
}