简体   繁体   中英

Calling Webservices in WP7

I am working on Windows Phone 7 platform and want to call the webservices for login, and other details.

But i am not getting the way to call the webserives. Can you please help me about how to call webservice in WP7.

Currently im using this

public string GetXmlResponse(string Url)
{            
    try
    {
        wr = WebRequest.Create(Url);
        hwr = (HttpWebRequest)wr;
        hwr.Method = "GET";
        hwr.ContentType = "text/xml";
        //hwr.Timeout = 2147483647;
        //hwr.ContentLength = URL.Length;
        IAsyncResult ar = null;
        ar = (IAsyncResult)hwr.BeginGetResponse(AsyncResponse, hwr);
    }
    catch
    {
        resp = null;
    }
    return resp;
}
public void AsyncResponse(IAsyncResult ar)
{            
    try
    {
        WebResponse ws = hwr.EndGetResponse(ar);
        StreamReader streader = new StreamReader(ws.GetResponseStream());
        resp = streader.ReadToEnd();
    }
    catch
    {
        resp = null;
    }            
}

But as it makes AsyncResponse, it returns me the null value, while calling the function GetXmlResponse.

Please help me for any thing.

Thanks

have you checked out the XNA site? http://create.msdn.com/en-US/ There is a link that goes to channel 9's Windows phone 7 development tutorials. One of the lessons that is on the second day I believe has a really good video of how to use web services.

By creating the delegate i have handled this.

In AsyncResponse i fire the delegate and on my form that fires the event for me.

This is how i am able to manage this.

i refered this link to create the delegate.

Thanks BHAVIK GOYAL

Try using HttpWebRequest.Create

wr = HttpWebRequest.Create(Url);

Also if the 'Method' is "GET", ContentType is not required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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