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
私はこれに完全に混乱しており、どんな助けでも大歓迎です。