Skip to main content

Hi, I'm trying to determine if it's possible to display a Forecast for a United States Zip code in a SmartForm/View.  The Webserice I'm using to test is: http://wsf.cdyne.com/WeatherWS/Weather.asmx?op=GetCityForecastByZIP and the value I'm using to invoke the service is 02766.

 

I create an Endpoints Web Service instance using the asmx web service.  Then I auto generate the smart objects using the Smart Object Tester utility.  When calling the GetCityForecastByZip method it appears the returning data has nested serialized data.  If you look at the XML that is returned from the service (see below) you'll notice how each "Forecast" element has a "Tempatures" and "ProbabiltyOfPrecipitation" element.  This results in nested serialized data as the Forecast Result element is serialized into a Forecast array.  Each Forecast item them has serialized Temperatures and POP's. There is also an example of this serialized JSON data below.

 

What I'm ultimately trying to do is display a typical weather forecast using existing smart object, view, and form functionality to list City/State information then each days forecast.   So for example, using the zip code above it would show:

 

Norton, MA

Forecast:

8/5/2014 Partly Cloudy  50 degrees

     

8/6/2014 Sunny  60 degrees

 

...and so on.

 

 

I can get the Date, WeatherID, and Description to display properly, but am unable to determine how to deserialize the Temperature and POP.

 

Any and all help is appreciated.

 

Thank you.

 

XML Returned from weather webservice.

<ForecastReturn>
    <Success>true</Success>
    <ResponseText>City Found</ResponseText>
    <State>MA</State>
    <City>Norton</City>
    <WeatherStationCity>Taunton</WeatherStationCity>
    <ForecastResult>
        <Forecast>
            <Date>2014-08-05T00:00:00</Date>
            <WeatherID>2</WeatherID>
            <Desciption>Partly Cloudy</Desciption>
            <Temperatures>
                <MorningLow/>
                <DaytimeHigh>84</DaytimeHigh>
            </Temperatures>
            <ProbabilityOfPrecipiation>
                <Nighttime/>
                <Daytime>10</Daytime>
            </ProbabilityOfPrecipiation>
        </Forecast>
        <Forecast>
            <Date>2014-08-06T00:00:00</Date>
            <WeatherID>1</WeatherID>
            <Desciption>Thunder Storms</Desciption>
            <Temperatures>
                <MorningLow>65</MorningLow>
                <DaytimeHigh>79</DaytimeHigh>
            </Temperatures>
            <ProbabilityOfPrecipiation>
                <Nighttime>30</Nighttime>
                <Daytime>50</Daytime>
            </ProbabilityOfPrecipiation>
        </Forecast>
    </ForecastResult>
</ForecastReturn>

 

Forecast Result Array

{
"$type": "Forecast3], WeatherService2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"$values": >
{
"$type": "Forecast, WeatherService2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"Date": "2014-08-05T00:00:00",
"WeatherID": 2,
"Desciption": "Partly Cloudy",
"Temperatures": {
"$type": "temp, WeatherService2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"MorningLow": "",
"DaytimeHigh": "84"
},
"ProbabilityOfPrecipiation": {
"$type": "POP, WeatherService2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"Nighttime": "",
"Daytime": "10"
}
},
{
"$type": "Forecast, WeatherService2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"Date": "2014-08-06T00:00:00",
"WeatherID": 1,
"Desciption": "Thunder Storms",
"Temperatures": {
"$type": "temp, WeatherService2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"MorningLow": "65",
"DaytimeHigh": "79"
},
"ProbabilityOfPrecipiation": {
"$type": "POP, WeatherService2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"Nighttime": "30",
"Daytime": "50"
}
}
]
}

 

 

One way of getting this to work would be to

 

create a service object project.

add a service reference to the asmx web service in that project

call the webservice and parse through the xml that the webservice returns using the .net DLLs.

return the items that you have parsed via the service object method.

 

Let me know if you require more information.

Hope this helps

 

 


I was in a similar situation and found the following solution.

 

If a web service returns a complex type the result is returned as a memo with a json value. The name or the return property contains the name of the compley type. The name of the type is also part of the json value, it's the value of the $type property. In most cases there should be a coresponding item in the folder 'Object Types' of the service instance. This type has the necessary serialize & deserialize methods to process the respnse.

 

In your case the web service response of GetCityWeatherByZIP(String ZIP) the return property ForecastResult(Forecasta]) (Memo)  has the value

{"$type":"Forecastc], WeahterService, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","$values":e{"$type":"Forecast,....}}]}

 

If you execute the Method "Deserialize Typed Array" of the SmartObject "Forecast" in the folder "Object types" you get an array of the Forecasts.  This is one of the array values:
{"$type":"Forecast, WeahterService, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","Date":"2014-08-05T00:00:00","WeatherID":2,"Desciption":"Partly Cloudy","Temperatures":{"$type":"temp, WeahterService, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","MorningLow":"","DaytimeHigh":"84"},"ProbabilityOfPrecipiation":{"$type":"POP, WeahterService, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","Nighttime":"","Daytime":"10"}}

 

You have to pass this value again to the Forecast object but this time you need to use the Deserialize method. Unfortunatly the temperatures are a complex type and you get again a json value.

{"$type":"temp, WeahterService, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null","MorningLow":"","DaytimeHigh":"84"}

 

You are probably guessing it and you are right, you need to pass this value to another smart object. This time its the "temp" smart object. After you executed the deserialize method you can finally access the  values of the properties MonringLow and DaytimeHigh.

 

I have to use the same approach with the user profile service of sharepoint and would be glad if there were an other no code solution.

 


Hi Krueger, thanks for the reply. I've previously gotten to the point where I have the typed Forecast object, and can work with those parameters. However, I'm unsure how to set up the smart object to deserialize each "temp" json object.  Based on your last statement about a no code solution, are you inferring that what I'm trying to do cannot be done without writing my own service provider or custom code?

 

I've attached a screen shot of how I've set up my smart object method if it helps. I've passed the tempatures value to the Deserialize call for the "temp" object, but it does not appear to work.  Any thoughts are appreciated?


17130iD296265EC8AE434F.png

 

Hi SethYuka, unfortunatly I'm also having the same issue as you. I just cannot figure out to create a working smart object and I'm not even sure that it is feasible. I created a new thread for this here.

 

I had another idea how you could achive your ultimate goal but it didn't work out. My approch was to design a view  wich lists the forecasts. The view is consumed by a weather form. When the weather form is initialized the forecast web service is called and the forecast array is passed to the forecast view. This is working fine as you can see:

11885i5CB45E19EDC6DB5B.png

After I got this working I wanted to do something like "execute smart object method on each item" pass the temperatur value of the item to it and populate the other missing properties/controls. At least this was my idea but I was not able to make it work. :(

 

 

 


11966i011A5DCBECCF7449.png

Yup, I tried the same thing with the views, and ended up running into the same issue you did.

 

Can someone from K2 chime in on this?


Reply