Windows Phone 7 中的 SOAP 解析 [英] SOAP Parsing in windows phone 7

查看:27
本文介绍了Windows Phone 7 中的 SOAP 解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会从 10 天开始搜索,但我在 wp7 中没有成功解析肥皂.

I will searching since 10 days but i have not succeed in soap parsing in wp7.

我的代码如下.我得到远程服务器返回错误:NotFound.和 System.Net.WebException.

My code is below. I get the The remote server returned an error: NotFound. and System.Net.WebException.

代码如下:

 private const string AuthServiceUri = "http://manarws.org/WS/manarService.asmx";
    private const string AuthEnvelope =
                       @"<?xml version=""1.0"" encoding=""utf-8""?>
                    <soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
                        <soap:Body>
                            <fnGetNewsResponse xmlns=""http://tempuri.org/"">
                               <fnGetNewsResult></fnGetNewsResult>
                               </fnGetNewsResponse>                
                        </soap:Body>
                    </soap:Envelope>";

 public void Authenticate()
    {
        HttpWebRequest spAuthReq = HttpWebRequest.Create(AuthServiceUri) as HttpWebRequest;
        spAuthReq.Headers["SOAPAction"] = "http://tempuri.org/fnGetNews";
        spAuthReq.ContentType = "text/xml; charset=utf-8";
        spAuthReq.Method = "POST";
        spAuthReq.BeginGetRequestStream(new AsyncCallback(spAuthReqCallBack), spAuthReq);
    }

 private void spAuthReqCallBack(IAsyncResult asyncResult)
    {
        UTF8Encoding encoding = new UTF8Encoding();
        HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
        System.Diagnostics.Debug.WriteLine("REquest is :" + request.Headers);
        Stream _body = request.EndGetRequestStream(asyncResult);
        string envelope = string.Format(AuthEnvelope,"","");
        System.Diagnostics.Debug.WriteLine("Envelope is :" + envelope);
        byte[] formBytes = encoding.GetBytes(envelope);
        _body.Write(formBytes, 0, formBytes.Length);
        _body.Close();
        request.BeginGetResponse(new AsyncCallback(ResponseCallback), request);
    }

 private void ResponseCallback(IAsyncResult asyncResult)
    {
        System.Diagnostics.Debug.WriteLine("Async Result is :" + asyncResult);

        HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
        HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);

        System.Diagnostics.Debug.WriteLine("Response is :::::::::::::::::::----" + request.EndGetResponse(asyncResult));

        if (request != null && response != null)
        {
            if (response.StatusCode == HttpStatusCode.OK)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());
                string responseString = reader.ReadToEnd();
            }
        }
    }

我在 HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult); 行中收到错误...

I get the error in HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult); line...

所以,请帮帮我.

谢谢.

推荐答案

按照以下步骤了解如何使用 SOAP 服务

Follow these steps to know how to use a SOAP service

-- Create a new project.
-- Right-click on the Project name and click on "Add Service Reference"...
   Then provide address as "http://manarws.org/WS/manarService.asmx?wsdl" and click Go.
-- Once service information is downloaded, provide Namespace something like
   "MyMemberService" at the bottom and click Ok.

现在您的代理类应该准备好了.
转到您的 Mainpage.xaml.cs 并在那里输入client".您可能应该得到一个名为ManarServiceClient"的类.

Now that your proxy classes should be ready.
Go to your Mainpage.xaml.cs and type 'client' there..you should probably get a class with the name "ManarServiceClient".

如果你明白了,那么尝试调用该类的合适方法.

If you get that, then try to call the suitable methods of that class.

举个例子

ManarServiceClient client = new ManarServiceClient();
client.fnGetNewsResponseCompleted += new EventHandler<fnGetNewsResponseCompletedEventArgs>(client_fnGetNewsResponseCompleted);
client.fnGetNewsResponseAsync();

注意:我没有使用我的工作系统,所以不能给你确切的代码.以上所有内容都是猜测的代码,将为您指明正确的方向.将测试我的代码并很快更新.

Note: I am not with my working system, so cannot give you exact code. All the above is a guessed code and shall point you in the right direction. Will test my code and update soon.

这篇关于Windows Phone 7 中的 SOAP 解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆