简体   繁体   English

使用C#消耗枚举类型的Web服务的问题

[英]issue using C# to consume web service with enum type

I'm having an issue consuming a web service and hoped someone could shed some light. 我在使用Web服务时遇到了问题,希望有人能提供一些帮助。

I have everything I need working with the exception of an enum. 除枚举外,我拥有所有需要的工作。

Generated Reference.cs contains: 生成的Reference.cs包含:

public enum SearchType {
    sales,
    lettings,
}

My controller method has the following: 我的控制器方法具有以下特点:

if (model.ValuationType == "lettings")
{
    Debug.WriteLine("in the lettings route");
    request = new ValuationRequest
    {
        ValuationType = SearchType.lettings,
        Postcode = model.Postcode,
        FromDate = DateTime.Now.AddDays(1),
        ToDate = DateTime.Now.AddDays(14)
    };
}
else 
{
    Debug.WriteLine("in the sales route");
    request = new ValuationRequest
    {
        ValuationType = SearchType.sales,
        Postcode = model.Postcode,
        FromDate = DateTime.Now.AddDays(1),
        ToDate = DateTime.Now.AddDays(14)
    };
}

var valuationAppointments = 
WebUtility.GetValuationAppointments(request);

and within GetValuationAppointments the utility simply does the following: GetValuationAppointments该实用程序只需执行以下操作:

public static Appointment[] GetValuationAppointments(ValuationRequest request)
{
    Debug.WriteLine(request.ValuationType);
    Debug.WriteLine(request.Postcode);
    Debug.WriteLine(request.FromDate);
    Debug.WriteLine(request.ToDate);

    service = new MyWebService();
    var valuationAppointments = service.GetValuationAppointments(request);
    return valuationAppointments;
}

Now the debug from those write lines is showing everything exactly as I would have expected and returns appointments correctly, however, they are always sales. 现在,这些写入行中的调试可以完全显示我所期望的一切,并正确返回约会,但是,它们始终是销售产品。 Even if lettings is passed through from the model to the service. 即使将租借从模型传递到服务。 My guess is something about the enum type is being completely ignored and so the service is defaulting to sales. 我的猜测是有关枚举类型的信息已被完全忽略,因此该服务默认为销售。

Visual Studio shows no warnings about ValuationType = SearchType.lettings and anything else I try with that line throws errors. Visual Studio不会显示有关ValuationType = SearchType.lettings警告,而我尝试使用该行进行的其他任何操作都会引发错误。

Any ideas at all why this ValuationType = SearchType.lettings is the only field failing? 有什么想法为什么这个ValuationType = SearchType.lettings是唯一失败的字段?

evidence from debug: 调试证据:

in the lettings route
lettings
GU4 7QG
29/08/2018 10:47:21
11/09/2018 10:47:21

Appreciate any help! 感谢任何帮助!

The issue was that I wasn't specifying some mandatory field 问题是我没有指定一些必填字段

SearchTypeSpecified = true;

fixed the issue! 解决了这个问题!

Cheers all the same folks. 所有人都欢呼雀跃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM