首页 新闻 会员 周边 捐助

ajax请求webservice soap协议数据

0
[待解决问题]

ajax怎样请求webservice soap协议数据?一直出问题,有没有会的大神解答一下

夜之独行者的主页 夜之独行者 | 菜鸟二级 | 园豆:202
提问于:2017-03-24 16:14
< >
分享
所有回答(2)
0

你抓一下http soap包就清楚了。

花飘水流兮 | 园豆:13615 (专家六级) | 2017-03-24 16:17

他给出的数据完全看不懂啊  我能加你为好友,请教一下吗?谢谢。我的qq:1084596970

支持(0) 反对(0) 夜之独行者 | 园豆:202 (菜鸟二级) | 2017-03-24 16:51

@夜之独行者: 送点豆就行了,幸苦给你翻一阵以前的代码,自己慢慢看。

using System;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
using System.Text;
using System.Windows.Controls;
using System.Xml.Linq;
using VMS.Controls;
using VMS.Utils;
using VMS.Views.MainPageItems.QueryItems.ParamQueryControlItems;

namespace VMS.Views.MainPageItems.QueryItems
{
public abstract class QueryBase : UserControl, IReflactor
{
public const string SpaceName = "VMS.Views.MainPageItems.QueryItems.BussinessQuerys.";
public static readonly Assembly CurrentAssembly = Assembly.GetExecutingAssembly();
public static readonly string CurrentAssemblyName = CurrentAssembly.FullName;

protected QueryBase()
{
ParamsQuery = new List<IParamQuery>();
LoadingForm = new LoadingWindow();
SetFunParamValues(CreateQueryParams());
DownloadSucesss += OnDownloadData;
}

public string Data { get; private set; }

/// <summary>
/// 除去Host的相对Uri
/// </summary>
public abstract string Uri { get; }

public abstract string Fun { get; }
public List<IParamQuery> ParamsQuery { get; private set; }
public LoadingWindow LoadingForm { get; private set; }

public virtual string Caption
{
get { return GetType().Name; }
}

public virtual string FullName
{
get { return GetType().FullName; }
}

public event Action<string> DownloadSucesss;
public virtual event Action<Exception> OnError;

private void SetFunParamValues(IList<IParamQuery> paramsControls)
{
if (paramsControls == null) return; //throw new FormatException("查询参数不能为NULL");
ParamsQuery.AddRange(paramsControls);
}

protected abstract IList<IParamQuery> CreateQueryParams();

private string CreateBody()
{
var contentBody = new StringBuilder();
contentBody.Append("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">");
contentBody.Append(
"<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");

contentBody.AppendFormat("<{0} xmlns=\"http://tempuri.org/\">", Fun);
foreach (IParamQuery funParam in ParamsQuery)
contentBody.AppendFormat("<{0}>{1}</{0}>", funParam.PName, funParam.PValue);
contentBody.AppendFormat("</{0}>", Fun);

contentBody.Append("</s:Body>");
contentBody.Append("</s:Envelope>");
return contentBody.ToString();
}

protected abstract Exception Validate();

protected virtual bool ValidateDealling(Exception ex)
{
if (ex == null)
{
return true;
}
if (OnError != null) OnError.Invoke(ex);
return false;
}

public virtual void LoadData()
{
if (LoadingForm.IsDownloading) return;
if (!ValidateDealling(Validate())) return;
LoadingForm.Show();
var webClient = new WebClient();
webClient.UploadStringCompleted += (sender, args) =>
{
if (!LoadingForm.IsDownloading) return;
if (args.Error != null)
{
if (OnError != null) OnError.Invoke(new NetWorkException("网络错误", args.Error));
}
else if (args.Result == null)
{
if (OnError != null) OnError.Invoke(new NetWorkException("数据错误", args.Error));
}
else
{
try
{
XDocument doc = XDocument.Parse(args.Result);
Data = doc.Root.Value;
if (DownloadSucesss != null) DownloadSucesss.Invoke(Data);
}
catch (Exception ex)
{
OnError.Invoke(new NetWorkException("数据读取错误", ex));
}
}
LoadingForm.Close();
};
webClient.Headers["SOAPAction"] = string.Format("http://tempuri.org/{0}", Fun);
webClient.Headers["Content-Type"] = "text/xml; charset=utf-8";
string soapBody = CreateBody();
webClient.UploadStringAsync(
new Uri(string.Format("http://{0}:8001/{1}", WebServiceHelper.Host, Uri), UriKind.Absolute), soapBody);
}

protected abstract void OnDownloadData(string content);
}
}

支持(0) 反对(0) 花飘水流兮 | 园豆:13615 (专家六级) | 2017-03-25 10:36

@夜之独行者: 代码是Silverlight的,貌似这个是完全兼容的。自己慢慢研究哈。

支持(0) 反对(0) 花飘水流兮 | 园豆:13615 (专家六级) | 2017-03-25 10:37
0

一楼说的对.他也是http请求的.照着他的请求包发个一样的请求

吴瑞祥 | 园豆:29449 (高人七级) | 2017-03-24 16:28

我能加你qq请教一下吗?谢谢。我的qq:1084596970

支持(0) 反对(0) 夜之独行者 | 园豆:202 (菜鸟二级) | 2017-03-24 16:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册