开发者

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 i m 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜