WP7 / 8应用程序中的SOAP标头身份验证

时间:2013-09-10 09:12:43

标签: web-services windows-phone-7 soap windows-phone-8

我正在提供如下所示的网络服务:

                      POST /mobileservice.asmx HTTP/1.1
Host: services.segwaycommunications.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://services.segwaycommunications.com/ValidateUser"

<?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:Header>
    <PlatformAuthentication xmlns="http://services.segwaycommunications.com">
      <UserName>string</UserName>
      <Password>string</Password>
    </PlatformAuthentication>
  </soap:Header>
  <soap:Body>
    <ValidateUser xmlns="http://services.segwaycommunications.com">
      <username xmlns="">string</username>
      <password xmlns="">string</password>
      <resellerid xmlns="">int</resellerid>
    </ValidateUser>
  </soap:Body>
</soap:Envelope>

现在,我们可以看到soap header需要通过类platformauthentication进行身份验证。

任何人都可以帮助我如何使用此网络服务在Windows Phone 7/8应用程序中进行身份验证?

我搜索了很多,但没有给我一个合适的解决方案。

谢谢,如果有人可以提供帮助。

1 个答案:

答案 0 :(得分:0)

根据我的观点,Json解析是最好的

所以你需要下载Newtonsoft.Json dll来解析web服务

按照下面的步骤

步骤1:右键点击添加引用添加服务引用。

Step2:现在将您的Web服务链接放在服务引用上并按下go按钮,并添加服务的命名空间参考 enter image description here

第3步:现在使用.cs文件中的Newtonsoft.Json.Linq;名称空间添加

Step4:现在在cs文件中添加以下代码

 WhatsupServices.WhatsUpServiceSoapClient ws = new WhatsupServices.WhatsUpServiceSoapClient();
ws.ContactUsJSONCompleted += ws_ContactUsJSONCompleted;
ws.ContactUsJSONAsync(txtContactUsName.Text, txtContactUsPhone.Text, txtContactUsEmail.Text, txtContactUsComment.Text);

step6:现在生成你的resopnce方法

 void ws_ContactUsJSONCompleted(object sender, dynamic e)
        {
            if (e.Error != null)
            {
                MessageBox.Show(LogIn.NetworkBusyMsg, LogIn.MsgHdr, MessageBoxButton.OK);
                busyIndicator.IsRunning = false;
            }
            else
            {
                busyIndicator.IsRunning = false;
                string Result = e.Result;
                JObject obj = JObject.Parse(Result);
                string ResultCode = (string)obj["ResultCode"];
                string ResponceMessage = (string)obj["ResponseMessage"];

                if (ResultCode == "1")
                {
                    MessageBox.Show("Thank you for your message. We'll get back to you soon.", LogIn.MsgHdr, MessageBoxButton.OK);
                    NavigationService.GoBack();
                }
                else
                {

                }
            }
        }

希望它会对你有所帮助。

如果有任何查询,请在此处发表评论。我会帮助您

肥皂头认证

soap header authentication solve in stack overflow

Custom authentication for web service using soap header

Using SOAP Headers to Validate Clients

相关问题