在使用PDA(WinCE)引用 webservice,需要把wbservice地址提取出来放入配置文件当中。在这里涉及了两个问题。在网上找的资料
第一:怎么提取
第二:PDA 属于跨平台
现在先处理怎么提取:
首先我们在PDA引用服务器的WebService比如为:WS_SellManage, 然后在PDA项目里创建一个代理类 DynWebServiceSell.cs,并继承这个webservice的类,在这里为WS_SellManage.SW_SellManage
[System.Diagnostics.DebuggerStepThrough(),
System.ComponentModel.DesignerCategory("code"),
System.Web.Services.WebServiceBinding(Name = "", Namespace = "")]
public class DynWebServiceSell: WS_SellManage.SW_SellManage//继承webservice
{
public DynWebServiceSell(string webUrl)
: base()
{
this.Url = webUrl;
}
}
创建一个app.config用来保存webservice地址。如下
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="WS_SellManageKey" value="http://190.160.10.79:80111/WebService/SW_SellManage.asmx"/>
</appSettings>
</configuration>
然后我们在 PDA窗体上的构造函数上使用这个代理类
DynWebServiceSell ws_Sell = null;
public Form1()
{
InitializeComponent();
//加载xml文档...
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\App.config";
System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();
xmldoc.Load(path);
System.Xml.XmlNode node = xmldoc.SelectSingleNode("//configuration/appSettings/add[@key='WS_SellManageKey']");
if (node != null)
{
ws_Sell = new DynWebServiceSell(node.Attributes["value"].Value);
}
}
使用:
object[] login = ws_Sell.Login(txtUserName.Text.Trim(), txtPassword.Text.Trim());//Login为webservice方法
第二个问题跨平台
如果是单单按上面的方式执行的话会出现:“webserver引用出现”服务器未能识别 HTTP 头 SOAPAction 的值“,按这个错误网上有很多解决的方式。在这里我找到的是需要在webservice类上加上
[SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
即:
/// <summary>
/// SW_SellManage 的Ì?摘a要°a说¦Ì明¡Â
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若¨?要°a允¨º许¨ª使º1用®? ASP.NET AJAX 从䨮脚?本À?中D调Ì¡Â用®?此ä? Web 服¤t务?,ê?请?取¨?消?对?下?行D的Ì?注Á¡é释º¨ª。¡ê
// [System.Web.Script.Services.ScriptService]
[SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
public class SW_SellManage : System.Web.Services.WebService
{
/// <summary>
/// </summary>
/// <returns></returns>
[WebMethod]
public object[] Login(string userName, string password)
{}
}
这样就不会出现问题了。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 【.NET】调用本地 Deepseek 模型
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库