有没有这一类的参考文档或者接口实例?(本人首次开发接口,对这流程操作都不是很了解,希望给个意见)
最简单的,如果存在mex,那么vs直接引用,当普通类使用。
再给你个http封装soap的方法,其他的给你讲也讲不撑钭~
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);
}
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();
}