在创建 WCF Rest 服务时,我注意到并非我的 Web 服务中的所有参数都在我的实现中。
这是界面:
[ServiceContract(Namespace="http://example.com/recordservice")]
public interface IBosleySchedulingServiceImpl
{
[OperationContract]
[WebInvoke(UriTemplate = "Record/Create",
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare, Method = "POST")]
string CreateRecord(Record record);
}
[DataContract(Namespace="http://example.com/recordservice")]
public class Appointment
{
[DataMember]
public int ResponseType { get; set; }
[DataMember]
public int ServiceType { get; set; }
[DataMember]
public string ContactId { get; set; }
[DataMember]
public string Location { get; set; }
[DataMember]
public string Time { get; set; }
}
我将这个 XML 传递给:
<Appointment xmlns="http://ngs.bosley.com/BosleySchedulingService">
<ContactId>1123-123</ContactId>
<Location>Fresno</Location>
<Time>2012-05-05T08:30:00</Time>
<ResponseType>45</ResponseType>
<ServiceType>45</ServiceType>
</Appointment>
在我的服务中,我只是将值输出到日志中,以便我可以暂时验证这些值是否通过:
logger.Debug("ContactId: " + appointment.ContactId);
logger.Debug("Time Field: " + appointment.Time);
logger.Debug("Location: " + appointment.Location);
logger.Debug("Response Type: " + Convert.ToInt32(appointment.ResponseType));
logger.Debug("ServiceType: " + Convert.ToInt32(appointment.ServiceType));
但是,在我的输出中,整数值为零:
ContactId: 1123-123
Time Field: 2012-05-05T08:30:00
Location: Fresno
Response Type: 0
ServiceType: 0
当我从 DataContract 和服务实现中删除字符串时,整数值没有问题。
Response Type: 45
ServiceType: 45
我对此感到非常困惑,任何帮助将不胜感激。