locked
Webservice\PHP Question RRS feed

  • Question

  • Hello Everyone,
    I'm working on a project where my customer has a PHP driven website which deals with medication information.  I've already looked into the PHP library, but i don't believe this has the functionality for querying medication information on health vault as of today (01/12/2010).

    My next proposed solution would be to create a web service using the .NET SDK from which the PHP website will communicate through.

    I'd like to know how plausible this solution sounds, and as to whether there's any documentation, or tutorials on setting this type of functionality up.

    The basic functionality i want is when the user clicks a button called copy from health vault, the PHP will call to a web service that i will create.  This web service will do the appropriate authentication and communication with Health vault, and then will return the medication information in XML format.

    If anyone has experience in implementing this type of functionality, or just has a helpful suggestion I'd really appreciate your input.

    Thanks
    Steve
    Tuesday, January 12, 2010 3:58 PM

Answers

  • It is a plausible solution and we have done it in the past

    At a high level, you need to implement the shell redirections using PHP until the point you get the wctoken.  You can then store it in session or cookie or whatever so that it can be further passed to the webservice implemented using .Net SDK which will proxy your calls to HealthVault Platform Services.

    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    • Marked as answer by smbialec Tuesday, January 12, 2010 8:02 PM
    Tuesday, January 12, 2010 4:10 PM
  • Hello Steve,

    Following is a sample web service I developed on .Net SDK. In the sample I am dealing with weight item. You can modify the code accordingly as the code flow will remain the same.

    First the client has to call this method to get the redirection URL.
            [WebMethod(EnableSession = true)]
            public string GetAuthenticationUrl()
            {
                return WebApplicationConfiguration.ShellAuthenticationUrl.ToString();
            }

    Then once the redirection is done from the client the control will be transferred to the action URL. From the action URL retrieve the wcToken and using the wcToken call the following method.
            [WebMethod(EnableSession = true)]
            public string GetPersonInfo(string authToken)
            {
                personInfo = WebApplicationUtilities.GetPersonInfo(authToken);
                WebApplicationUtilities.SavePersonInfoToCookie(HttpContext.Current, personInfo);

                return personInfo.Name;
            }

    Once the PersonInfo is saved into the cookie please remember to use the same CookieContainer for future calls to the web service.
            [WebMethod(EnableSession = true)]
            public string GetPersonName()
            {
                if (personInfo == null)
                {
                    personInfo = WebApplicationUtilities.LoadPersonInfoFromCookie(HttpContext.Current);

                    return personInfo.Name;
                }

                return string.Empty;
            }

    Then you can call the custom made functions to insert or retrieve the data as needed.
            [WebMethod(EnableSession = true)]
            public bool InsertWeight(int value)
            {
                if (personInfo == null)
                {
                    personInfo = WebApplicationUtilities.LoadPersonInfoFromCookie(HttpContext.Current);
                }
               
                personInfo.SelectedRecord.NewItem(new Weight(new HealthServiceDateTime(DateTime.Now), new WeightValue(value)));

                return true;
            }

    Please keep the flag <add key="WCPage_UseAspSession" value="true"/> in the web service's web.config. I tested this using a C# client as I am not familiar with the PHP environment. Please let me know if you are facing any further issue on this.

    Hope this helps.

    Thanks and Regards,
    Aneesh D.
    • Proposed as answer by Aneesh D Tuesday, January 12, 2010 7:08 PM
    • Marked as answer by smbialec Tuesday, January 12, 2010 8:02 PM
    Tuesday, January 12, 2010 5:54 PM
  • The property PersonInfo is present in the HealthServicePage. But as your class CopyTo is deriving from WebService and not from HealthServicePage you cannot use the PersonInfo property inside this class.

    For this you will have to declare a variable like PersonInfo personInfo = WebApplicationUtilities.GetPersonInfo(authToken); and then use that variable to retrieve the Name property (e.g, personInfo.Name). You can also declare the variable with a class scope according to your scenario.

    Thanks and Regards,
    Aneesh D.
    • Proposed as answer by Aneesh D Tuesday, January 12, 2010 10:13 PM
    • Marked as answer by smbialec Tuesday, January 12, 2010 11:09 PM
    Tuesday, January 12, 2010 10:12 PM

All replies

  • It is a plausible solution and we have done it in the past

    At a high level, you need to implement the shell redirections using PHP until the point you get the wctoken.  You can then store it in session or cookie or whatever so that it can be further passed to the webservice implemented using .Net SDK which will proxy your calls to HealthVault Platform Services.

    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    • Marked as answer by smbialec Tuesday, January 12, 2010 8:02 PM
    Tuesday, January 12, 2010 4:10 PM
  • Hello Steve,

    Following is a sample web service I developed on .Net SDK. In the sample I am dealing with weight item. You can modify the code accordingly as the code flow will remain the same.

    First the client has to call this method to get the redirection URL.
            [WebMethod(EnableSession = true)]
            public string GetAuthenticationUrl()
            {
                return WebApplicationConfiguration.ShellAuthenticationUrl.ToString();
            }

    Then once the redirection is done from the client the control will be transferred to the action URL. From the action URL retrieve the wcToken and using the wcToken call the following method.
            [WebMethod(EnableSession = true)]
            public string GetPersonInfo(string authToken)
            {
                personInfo = WebApplicationUtilities.GetPersonInfo(authToken);
                WebApplicationUtilities.SavePersonInfoToCookie(HttpContext.Current, personInfo);

                return personInfo.Name;
            }

    Once the PersonInfo is saved into the cookie please remember to use the same CookieContainer for future calls to the web service.
            [WebMethod(EnableSession = true)]
            public string GetPersonName()
            {
                if (personInfo == null)
                {
                    personInfo = WebApplicationUtilities.LoadPersonInfoFromCookie(HttpContext.Current);

                    return personInfo.Name;
                }

                return string.Empty;
            }

    Then you can call the custom made functions to insert or retrieve the data as needed.
            [WebMethod(EnableSession = true)]
            public bool InsertWeight(int value)
            {
                if (personInfo == null)
                {
                    personInfo = WebApplicationUtilities.LoadPersonInfoFromCookie(HttpContext.Current);
                }
               
                personInfo.SelectedRecord.NewItem(new Weight(new HealthServiceDateTime(DateTime.Now), new WeightValue(value)));

                return true;
            }

    Please keep the flag <add key="WCPage_UseAspSession" value="true"/> in the web service's web.config. I tested this using a C# client as I am not familiar with the PHP environment. Please let me know if you are facing any further issue on this.

    Hope this helps.

    Thanks and Regards,
    Aneesh D.
    • Proposed as answer by Aneesh D Tuesday, January 12, 2010 7:08 PM
    • Marked as answer by smbialec Tuesday, January 12, 2010 8:02 PM
    Tuesday, January 12, 2010 5:54 PM
  • First off, thank you for that fast replies.  They both were very helpful.   I believe I understand what are describing.

    The issue I'm currently having though is Visual Studio is throwing an error on the PersonInfo when i place it into a .asmx Webservice file is...

      'Microsoft.Health.PersonInfo' is a 'type' but is used like a 'variable'  

    and

    An object reference is required for the non-static field, method, or property 'Microsoft.Health.PersonInfo.Name.get' 


    This is a similar error if a remove  :  HealthServicePage from the class declaration of an aspx file

    below is a small fragment of the code i have written

    using System;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using Microsoft.Health.ItemTypes;
    using Microsoft.Health.Web;
    using Microsoft.Health;

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class CopyTo  : System.Web.Services.WebService {

        [WebMethod(EnableSession = true)]
        public string GetPersonInfo(string authToken)
        {

            PersonInfo = WebApplicationUtilities.GetPersonInfo(authToken);
            WebApplicationUtilities.SavePersonInfoToCookie(HttpContext.Current, PersonInfo);

            return PersonInfo.Name;
        }
    }

    My guess is I'm messing up the class declaration, but I'm not sure where to start to fix this.

    Thanks
    Steve
    Tuesday, January 12, 2010 7:48 PM
  • The property PersonInfo is present in the HealthServicePage. But as your class CopyTo is deriving from WebService and not from HealthServicePage you cannot use the PersonInfo property inside this class.

    For this you will have to declare a variable like PersonInfo personInfo = WebApplicationUtilities.GetPersonInfo(authToken); and then use that variable to retrieve the Name property (e.g, personInfo.Name). You can also declare the variable with a class scope according to your scenario.

    Thanks and Regards,
    Aneesh D.
    • Proposed as answer by Aneesh D Tuesday, January 12, 2010 10:13 PM
    • Marked as answer by smbialec Tuesday, January 12, 2010 11:09 PM
    Tuesday, January 12, 2010 10:12 PM
  • Great Thanks Aneesh.  That seems to be working for me.

    Here's a look at the updated function incase anyone else had this issue

        [WebMethod(EnableSession = true)]
        public string GetPersonInfo(string authToken)
        {

            PersonInfo personInfo = WebApplicationUtilities.GetPersonInfo(authToken);
            WebApplicationUtilities.SavePersonInfoToCookie(HttpContext.Current, personInfo);

            return personInfo.Name;
        }
    Tuesday, January 12, 2010 11:10 PM