Using the WsMapper: no more ugly properties! - HodStudio/XitSoap GitHub Wiki

In old times, the models not every time have a good approach when naming classes and properties. It's not difficult to find web services that has totally ugly names, that doesn't follow the nowadays conventions used.

To avoid to have classes e properties with these ugly names, XitSoap implements an attribute called WsMapper, that makes the "translation" between your model and the model from the web service.

For example, this is the xml generated by the web service http://www.webservicex.net/uszip.asmx/GetInfoByZip.

<CITY>Phoenix</CITY>
<STATE>AZ</STATE>
<ZIP>85001</ZIP>
<AREA_CODE>602</AREA_CODE>
<TIME_ZONE>M</TIME_ZONE>

It has some properties that if we put it on our code, it will be something like:

public string CITY { get; set; }
public string STATE { get; set; }
public int ZIP { get; set; }
public int AREA_CODE { get; set; }
public string TIME_ZONE { get; set; }

Totally outside from the name conventions used today.

Now, take a look how it is using the WsMapper!

public class CityInfo
{
    [WsMapper("CITY")]
    public string Name { get; set; }
    [WsMapper("STATE")]
    public string State { get; set; }
    [WsMapper("ZIP")]
    public int ZipCode { get; set; }
    [WsMapper("AREA_CODE")]
    public int AreaCode { get; set; }
    [WsMapper("TIME_ZONE")]
    public string TimeZone { get; set; }
}

Using the WsMapper, you can create your model and insert it as parameter or just put it as the return from your call that the XitSoap will translate the properties direct to you!

⚠️ **GitHub.com Fallback** ⚠️