最近着手一个wince的小项目,调用用户的webservice做简单的查询修改操作。
客户的webservice是java写的(平台是livebos),我本地是用.net C#做的wince项目,
本身.net调用java的服务也没什么,感觉跟调用.net的服务差不多,在vs2008中创建智能项目,引入web地址,自动生成代理类,
问题来了,调用登录方法后,得不到返回的loginResult(它是web服务中的类,继承自lbeResult基类)对象。
/// <remarks/> [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://ws.livebos.apex.com/")] public partial class loginResult : lbeResult { private string sessionIdField; /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] public string sessionId { get { return this.sessionIdField; } set { this.sessionIdField = value; } } }
信息如下:
但是sessionId中有值,跟客户沟通(他说如果sessionId中有值说明服务上登录成功了)。但是,为什么基类中的属性为空呢?后来客户建议我使用原始的方法 发送soap报文的方法来测试结果是否正确。
/// <summary> /// 登录方法 /// </summary> /// <param name="userId"></param> /// <param name="password"></param> /// <returns></returns> public loginResult login(string userId, string password, out string errMsg) { errMsg = string.Empty; loginResult result = null; //根据URL创建请求对象 HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(serviceURL); webRequest.Method = "POST"; webRequest.ContentType = "text/xml;charset=\"utf-8\""; StringBuilder soap = new StringBuilder(); ////登录报文格式 ///* // * <q0:login> // * <userid>$userid</userid> // * <password>$password</password> // * <scheme>$scheme</scheme> // * <algorithm>$algorithm</algorithm> // * <securityCode></securityCode> // * </q0:login> // * * soap.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); soap.Append("<soapenv:Envelope xmlns:q0=\"http://ws.livebos.apex.com/\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"); soap.Append("<soapenv:Header>"); soap.Append("</soapenv:Header>"); soap.Append("<soapenv:Body>"); soap.Append("<q0:login>"); soap.Append("<userid>{0}</userid>"); soap.Append("<password>{1}</password>"); soap.Append("<scheme></scheme>"); soap.Append("<algorithm></algorithm>"); soap.Append("<securityCode></securityCode>"); soap.Append("</q0:login>"); soap.Append("</soapenv:Body> "); soap.Append("</soapenv:Envelope>"); //转换成字节数组 byte[] bytes = Encoding.UTF8.GetBytes(string.Format(soap.ToString(),userId,password)); webRequest.ContentLength = bytes.Length; Stream stream = webRequest.GetRequestStream(); stream.Write(bytes, 0, bytes.Length); stream.Flush(); stream.Close(); try { HttpWebResponse webResponse = webRequest.GetResponse() as HttpWebResponse; if (webResponse.StatusCode == HttpStatusCode.OK) { //获取返回结果流 Stream tempStraem = webResponse.GetResponseStream(); StreamReader sr = new StreamReader(tempStraem, Encoding.UTF8); //获取结果 string res = sr.ReadToEnd(); sr.Close();//关闭读取器 tempStraem.Close();//关闭流 //把结果先转换为xml文件 查询<LoginResult>节点,然后把它该节点再转换为类对象 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(res); XmlNode node = xmlDoc.SelectSingleNode("//LoginResult"); xmlDoc.LoadXml(node.OuterXml); //给文档添加<?xml version="1.0" encoding="utf-8"?> XmlDeclaration xmlDecl = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); xmlDoc.InsertBefore(xmlDecl, xmlDoc.DocumentElement); res = xmlDoc.InnerXml.Replace("LoginResult","loginResult"); //把xml转换成lbeResult对象 result = Deserialize(res,typeof(loginResult)) as loginResult; } } catch (WebException ex) { errMsg = ex.Message; } return result; }
最终得到的xml文件没有问题,里面的数据都正确,但是后来一步反序列化得到的类对象又和之前一样。??这真是百思不得其解...
后来不知道怎么得把代理中的loginResult类的特性注释掉后,却得到了正确的对象??
虽然不知道为什么?但要如果这样都好使的话也行啊,可是其它子类就没有那XX,无论是否注释类的特性,都不能得到正确结果
但有一点我要特别说明一下:我在vs2008中创建的是智能项目选择的是wince平台,编译生成的exe是直接可以在电脑上运行,如果在电脑直接运行是完成正确的没有任何问题的。但是只要放在终端设备里就会出现上面的问题。这点.....
最终也没有解决,希望高人指点,谢谢!
lbeResult 的类是如何定义的?
另外,你那段使用 httpwebRequest 的代码有问题,为什么要给文档添加<?xml version="1.0" encoding="utf-8"?>?为什么要 Replace("LoginResult","loginResult"),你要知道框架自动反序列化使用 Stream 的时候可不会这么麻烦。
我建议你把把响应的内容贴出来,你知道框架自动反序列话使用的是哪个序列化类吗?
首先感谢你的回答,下面我把问题补充一下:
lbeResult类
/// <remarks/> [System.Xml.Serialization.XmlIncludeAttribute(typeof(logoutResult))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(bizProcessResult))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(loginResult))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(createResult))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(workActionResult))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(workOwnerResponse))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(queryResult))] [System.Xml.Serialization.XmlIncludeAttribute(typeof(availableWorkActionResponse))] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://ws.livebos.apex.com/")] public partial class lbeResult { private string messageField; private int resultField; /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] public string message { get { return this.messageField; } set { this.messageField = value; } } /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] public int result { get { return this.resultField; } set { this.resultField = value; } } }
得到的结果
//获取结果
string res = sr.ReadToEnd();
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:loginResponse xmlns:ns2="http://ws.livebos.apex.com/">
<LoginResult>
<message>成功</message>
<result>1</result>
<sessionId>42e94330179401820cf02704efc1e530</sessionId>
</LoginResult>
</ns2:loginResponse>
</soap:Body>
</soap:Envelope>
要把它转换成loginResult对象,我就获取<LoginResult>节点并转换,
我添加<?xml version="1.0" encoding="utf-8"?>我当时把一个类对象序死之后得到的xml中有,所以我就在这里添加了,后面测试不添加也可以。 Replace("LoginResult","loginResult"),如果不把LoginResult转换为loginResult反序列化不成功,如下:
如果我把loginResult类的特性注释掉后,就可以把得到结果反序列化成功,如果取消注释就反序列化失败:
下面序列化与反序列化的方法:
/// <summary> /// 反序列化XML字符串为指定类型 /// </summary> public object Deserialize(string Xml, Type ThisType) { XmlSerializer xmlSerializer = new XmlSerializer(ThisType); object result; try { using (StringReader stringReader = new StringReader(Xml)) { //MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(Xml)); result = xmlSerializer.Deserialize(stringReader); } } catch (Exception innerException) { bool flag = false; if (Xml != null) { if (Xml.StartsWith(Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble(),0,Encoding.UTF8.GetPreamble().Length))) { flag = true; } } throw new ApplicationException(string.Format("Couldn't parse XML: '{0}'; Contains BOM: {1}; Type: {2}.", Xml, flag, ThisType.FullName), innerException); } return result; } /// <summary> /// 序列化object对象为XML字符串 /// </summary> public string Serialize(object ObjectToSerialize) { if (ObjectToSerialize == null) return null; string result = null; try { XmlSerializer xmlSerializer = new XmlSerializer(ObjectToSerialize.GetType()); using (MemoryStream memoryStream = new MemoryStream()) { XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, new UTF8Encoding(false)); xmlTextWriter.Formatting = Formatting.Indented; xmlSerializer.Serialize(xmlTextWriter, ObjectToSerialize); xmlTextWriter.Flush(); xmlTextWriter.Close(); UTF8Encoding uTF8Encoding = new UTF8Encoding(false, true); byte[] bytes = memoryStream.ToArray(); result = uTF8Encoding.GetString(bytes, 0, bytes.Length); } } catch (Exception innerException) { throw new ApplicationException("Couldn't Serialize Object:" + ObjectToSerialize.GetType().Name, innerException); } return result; }
@忽而今夏: 大小写肯定是有差别的,你移除是 Namespace,序列化同 Namespace 相关。你把 loginResult 的 [System.Xml.Serialization.XmlTypeAttribute(Namespace=http://ws.livebos.apex.com/)] 修改为 [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://ws.livebos.apex.com/",TypeName = "LoginResult")] 测试下。
@Launcher:
你好!修改代理类中的LoginResult,添加TypeName="LoginResult",无论是调用代理类中的方法 还是发送soap报文都不能得到正确的类对象。
我还想请教一个问题,web方法中需要一个类数组,我该怎么拼接soap报文,比如query方法:有一个lbParameter类型的数组
/// <remarks/> [System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace="http://ws.livebos.apex.com/", ResponseNamespace="http://ws.livebos.apex.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] [return: System.Xml.Serialization.XmlElementAttribute("QueryResult", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] public queryResult query([System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string sessionId, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string objectName, [System.Xml.Serialization.XmlElementAttribute("params", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] lbParameter[] @params, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] string condition, [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] queryOption queryOption) { object[] results = this.Invoke("query", new object[] { sessionId, objectName, @params, condition, queryOption}); return ((queryResult)(results[0])); }
报文格式:
//查询报文格式 ///* //<q0:query> // <sessionId>$sessionId</sessionId> // <objectName>$objectName</objectName> // <params>$params</params> // <condition>$condition</condition> // <queryOption> // <batchNo>$batchNo</batchNo> // <batchSize>$batchSize</batchSize> // <queryCount>$queryCount</queryCount> // <valueOption>$valueOption</valueOption> // <orderBy>$orderBy</orderBy> // <queryId>$queryId</queryId>> // </queryOption> //</q0:query> // * // * *
lbParameter类
/// <remarks/> [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://ws.livebos.apex.com/")] public partial class lbParameter { private string nameField; private string valueField; /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] public string name { get { return this.nameField; } set { this.nameField = value; } } /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] public string value { get { return this.valueField; } set { this.valueField = value; } } }
//参数数组
lbParameter[] parms =
{
new lbParameter(){ name="userid",value=userId},
new lbParameter(){name="password",value = password}
};
我该怎么把这个parms对象放在报文中,以什么样的格式??
@忽而今夏: 你把你这个 web service 的 wsdl 贴出来,另外你有用过 .Net Framework (不是用于 wince 的 Compact Framework)测试过吗(包括 web 引用和服务引用两种方式)?
@Launcher:你好!
webservice:http://hi-ray.vicp.cc:8099/service/LBEBusiness?wsdl
我还没有没用.net framework测试过,但是我在开始写的红色字体不知道你注意了没有,我选择的平台是windowsce,它可以在电脑上正常运行没有问题的!我想使用.net framework应该没有问题,回头我再测试一下。
@忽而今夏: 你那个地址我访问不了,能否把生成的 wsdl 直接贴出来。可以正常运行啊,那你怎么还问无法得到正确对象?
以.net framework方法测试没有问题
@Launcher:
This XML file does not appear to have any style information associated with it. The document tree is shown below. <wsdl:definitions xmlns:ns1="http://cxf.apache.org/bindings/xformat" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.livebos.apex.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="LBEBusinessWebService" targetNamespace="http://ws.livebos.apex.com/"> <wsdl:types> <xs:schema xmlns:tns="http://ws.livebos.apex.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://ws.livebos.apex.com/"> <xs:element name="create" type="tns:create"/> <xs:element name="createResponse" type="tns:createResponse"/> <xs:element name="delete" type="tns:delete"/> <xs:element name="deleteResponse" type="tns:deleteResponse"/> <xs:element name="doWorkAction" type="tns:doWorkAction"/> <xs:element name="doWorkActionByObject" type="tns:doWorkActionByObject"/> <xs:element name="doWorkActionByObjectResponse" type="tns:doWorkActionByObjectResponse"/> <xs:element name="doWorkActionResponse" type="tns:doWorkActionResponse"/> <xs:element name="execBizProcess" type="tns:execBizProcess"/> <xs:element name="execBizProcessResponse" type="tns:execBizProcessResponse"/> <xs:element name="getUserInfo" type="tns:getUserInfo"/> <xs:element name="getUserInfoResponse" type="tns:getUserInfoResponse"/> <xs:element name="getWorkAvailableAction" type="tns:getWorkAvailableAction"/> <xs:element name="getWorkAvailableActionResponse" type="tns:getWorkAvailableActionResponse"/> <xs:element name="getWorkOwner" type="tns:getWorkOwner"/> <xs:element name="getWorkOwnerResponse" type="tns:getWorkOwnerResponse"/> <xs:element name="login" type="tns:login"/> <xs:element name="loginResponse" type="tns:loginResponse"/> <xs:element name="logout" type="tns:logout"/> <xs:element name="logoutResponse" type="tns:logoutResponse"/> <xs:element name="query" type="tns:query"/> <xs:element name="queryResponse" type="tns:queryResponse"/> <xs:element name="queryTaskListByCondition" type="tns:queryTaskListByCondition"/> <xs:element name="queryTaskListByConditionResponse" type="tns:queryTaskListByConditionResponse"/> <xs:element name="queryTasks" type="tns:queryTasks"/> <xs:element name="queryTasksResponse" type="tns:queryTasksResponse"/> <xs:element name="queryWorkflowDescribe" type="tns:queryWorkflowDescribe"/> <xs:element name="queryWorkflowDescribeResponse" type="tns:queryWorkflowDescribeResponse"/> <xs:element name="update" type="tns:update"/> <xs:element name="updateResponse" type="tns:updateResponse"/> <xs:element name="validateUser" type="tns:validateUser"/> <xs:element name="validateUserResponse" type="tns:validateUserResponse"/> <xs:complexType name="getWorkAvailableAction"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> <xs:element name="instanceId" type="xs:long"/> </xs:sequence> </xs:complexType> <xs:complexType name="getWorkAvailableActionResponse"> <xs:sequence> <xs:element minOccurs="0" name="AvailableWorkActionResponse" type="tns:availableWorkActionResponse"/> </xs:sequence> </xs:complexType> <xs:complexType name="availableWorkActionResponse"> <xs:complexContent> <xs:extension base="tns:lbeResult"> <xs:sequence> <xs:element maxOccurs="unbounded" minOccurs="0" name="actions" nillable="true" type="tns:workAction"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="lbeResult"> <xs:sequence> <xs:element minOccurs="0" name="message" type="xs:string"/> <xs:element name="result" type="xs:int"/> </xs:sequence> </xs:complexType> <xs:complexType name="workAction"> <xs:sequence> <xs:element name="actionId" type="xs:int"/> <xs:element minOccurs="0" name="actionName" type="xs:string"/> <xs:element name="stepId" type="xs:int"/> <xs:element minOccurs="0" name="stepName" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="queryTasks"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> <xs:element minOccurs="0" name="caller" type="xs:string"/> <xs:element minOccurs="0" name="queryOption" type="tns:queryOption"/> </xs:sequence> </xs:complexType> <xs:complexType name="queryOption"> <xs:sequence> <xs:element name="batchNo" type="xs:int"/> <xs:element name="batchSize" type="xs:int"/> <xs:element minOccurs="0" name="orderBy" type="xs:string"/> <xs:element name="queryCount" type="xs:boolean"/> <xs:element minOccurs="0" name="queryId" type="xs:string"/> <xs:element minOccurs="0" name="valueOption" type="tns:valueOption"/> </xs:sequence> </xs:complexType> <xs:complexType name="queryTasksResponse"> <xs:sequence> <xs:element minOccurs="0" name="QueryResult" type="tns:queryResult"/> </xs:sequence> </xs:complexType> <xs:complexType name="queryResult"> <xs:complexContent> <xs:extension base="tns:lbeResult"> <xs:sequence> <xs:element name="count" type="xs:int"/> <xs:element name="hasMore" type="xs:boolean"/> <xs:element minOccurs="0" name="metaData" type="tns:lbMetaData"/> <xs:element minOccurs="0" name="queryId" type="xs:string"/> <xs:element maxOccurs="unbounded" minOccurs="0" name="records" nillable="true" type="tns:lbRecord"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="lbMetaData"> <xs:sequence> <xs:element maxOccurs="unbounded" minOccurs="0" name="colInfo" nillable="true" type="tns:colInfo"/> <xs:element name="columnCount" type="xs:int"/> </xs:sequence> </xs:complexType> <xs:complexType name="colInfo"> <xs:sequence> <xs:element minOccurs="0" name="label" type="xs:string"/> <xs:element name="length" type="xs:int"/> <xs:element minOccurs="0" name="name" type="xs:string"/> <xs:element name="scale" type="xs:int"/> <xs:element name="type" type="xs:int"/> </xs:sequence> </xs:complexType> <xs:complexType name="lbRecord"> <xs:sequence> <xs:element name="size" type="xs:int"/> <xs:element maxOccurs="unbounded" minOccurs="0" name="values" nillable="true" type="xs:anyType"/> </xs:sequence> </xs:complexType> <xs:complexType name="queryWorkflowDescribe"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> <xs:element minOccurs="0" name="uid" type="xs:string"/> <xs:element name="startupOnly" type="xs:boolean"/> </xs:sequence> </xs:complexType> <xs:complexType name="queryWorkflowDescribeResponse"> <xs:sequence> <xs:element minOccurs="0" name="UserInfo" type="tns:workflowDescribeResponse"/> </xs:sequence> </xs:complexType> <xs:complexType name="workflowDescribeResponse"> <xs:sequence> <xs:element maxOccurs="unbounded" minOccurs="0" name="workflowDescribes" nillable="true" type="tns:workflowDescribe"/> </xs:sequence> </xs:complexType> <xs:complexType name="workflowDescribe"> <xs:sequence> <xs:element name="attribute" type="xs:int"/> <xs:element minOccurs="0" name="category" type="xs:string"/> <xs:element minOccurs="0" name="describe" type="xs:string"/> <xs:element minOccurs="0" name="name" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="getWorkOwner"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> <xs:element name="instanceId" type="xs:long"/> <xs:element name="stepId" type="xs:int"/> </xs:sequence> </xs:complexType> <xs:complexType name="getWorkOwnerResponse"> <xs:sequence> <xs:element minOccurs="0" name="WorkOwnerResponse" type="tns:workOwnerResponse"/> </xs:sequence> </xs:complexType> <xs:complexType name="workOwnerResponse"> <xs:complexContent> <xs:extension base="tns:lbeResult"> <xs:sequence> <xs:element name="approveMode" type="xs:int"/> <xs:element maxOccurs="unbounded" minOccurs="0" name="owners" nillable="true" type="xs:string"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="doWorkActionByObject"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> <xs:element minOccurs="0" name="objectName" type="xs:string"/> <xs:element minOccurs="0" name="id" type="xs:string"/> <xs:element name="actionId" type="xs:int"/> <xs:element maxOccurs="unbounded" minOccurs="0" name="params" type="tns:lbParameter"/> <xs:element minOccurs="0" name="caller" type="xs:string"/> <xs:element minOccurs="0" name="summary" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="lbParameter"> <xs:sequence> <xs:element minOccurs="0" name="name" type="xs:string"/> <xs:element minOccurs="0" name="value" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="doWorkActionByObjectResponse"> <xs:sequence> <xs:element minOccurs="0" name="WorkActionResult" type="tns:workActionResult"/> </xs:sequence> </xs:complexType> <xs:complexType name="workActionResult"> <xs:complexContent> <xs:extension base="tns:lbeResult"> <xs:sequence> <xs:element name="instanceId" type="xs:long"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="getUserInfo"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> <xs:element minOccurs="0" name="loginId" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="getUserInfoResponse"> <xs:sequence> <xs:element minOccurs="0" name="UserInfo" type="tns:userInfo"/> </xs:sequence> </xs:complexType> <xs:complexType name="userInfo"> <xs:sequence> <xs:element name="grade" type="xs:int"/> <xs:element name="id" type="xs:long"/> <xs:element minOccurs="0" name="lastLogin" type="xs:string"/> <xs:element minOccurs="0" name="loginId" type="xs:string"/> <xs:element minOccurs="0" name="name" type="xs:string"/> <xs:element name="orgId" type="xs:long"/> <xs:element name="status" type="xs:int"/> </xs:sequence> </xs:complexType> <xs:complexType name="create"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> <xs:element minOccurs="0" name="objectName" type="xs:string"/> <xs:element maxOccurs="unbounded" minOccurs="0" name="params" type="tns:lbParameter"/> </xs:sequence> </xs:complexType> <xs:complexType name="createResponse"> <xs:sequence> <xs:element minOccurs="0" name="CreateResult" type="tns:createResult"/> </xs:sequence> </xs:complexType> <xs:complexType name="createResult"> <xs:complexContent> <xs:extension base="tns:lbeResult"> <xs:sequence> <xs:element minOccurs="0" name="id" type="xs:string"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="doWorkAction"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> <xs:element minOccurs="0" name="workflowName" type="xs:string"/> <xs:element name="instanceId" type="xs:long"/> <xs:element name="actionId" type="xs:int"/> <xs:element maxOccurs="unbounded" minOccurs="0" name="params" type="tns:lbParameter"/> <xs:element minOccurs="0" name="caller" type="xs:string"/> <xs:element minOccurs="0" name="summary" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="doWorkActionResponse"> <xs:sequence> <xs:element minOccurs="0" name="WorkActionResult" type="tns:workActionResult"/> </xs:sequence> </xs:complexType> <xs:complexType name="delete"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> <xs:element minOccurs="0" name="objectName" type="xs:string"/> <xs:element minOccurs="0" name="id" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="deleteResponse"> <xs:sequence> <xs:element minOccurs="0" name="LBEResult" type="tns:lbeResult"/> </xs:sequence> </xs:complexType> <xs:complexType name="login"> <xs:sequence> <xs:element minOccurs="0" name="userid" type="xs:string"/> <xs:element minOccurs="0" name="password" type="xs:string"/> <xs:element minOccurs="0" name="scheme" type="xs:string"/> <xs:element minOccurs="0" name="algorithm" type="xs:string"/> <xs:element minOccurs="0" name="securityCode" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="loginResponse"> <xs:sequence> <xs:element minOccurs="0" name="LoginResult" type="tns:loginResult"/> </xs:sequence> </xs:complexType> <xs:complexType name="loginResult"> <xs:complexContent> <xs:extension base="tns:lbeResult"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="validateUser"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> <xs:element minOccurs="0" name="userId" type="xs:string"/> <xs:element minOccurs="0" name="password" type="xs:string"/> <xs:element minOccurs="0" name="algorithm" type="xs:string"/> <xs:element minOccurs="0" name="securityCode" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="validateUserResponse"> <xs:sequence> <xs:element minOccurs="0" name="UserInfo" type="tns:queryResult"/> </xs:sequence> </xs:complexType> <xs:complexType name="queryTaskListByCondition"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> <xs:element minOccurs="0" name="caller" type="xs:string"/> <xs:element minOccurs="0" name="condition" type="tns:workCondition"/> <xs:element minOccurs="0" name="queryOption" type="tns:queryOption"/> </xs:sequence> </xs:complexType> <xs:complexType name="workCondition"> <xs:sequence> <xs:element minOccurs="0" name="beginTime" type="xs:string"/> <xs:element minOccurs="0" name="dateRange" type="xs:string"/> <xs:element minOccurs="0" name="endTime" type="xs:string"/> <xs:element name="incEntrust" type="xs:boolean"/> <xs:element name="status" type="xs:int"/> <xs:element minOccurs="0" name="subject" type="xs:string"/> <xs:element minOccurs="0" name="type" type="xs:string"/> <xs:element minOccurs="0" name="workName" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="queryTaskListByConditionResponse"> <xs:sequence> <xs:element minOccurs="0" name="QueryResult" type="tns:queryResult"/> </xs:sequence> </xs:complexType> <xs:complexType name="query"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> <xs:element minOccurs="0" name="objectName" type="xs:string"/> <xs:element maxOccurs="unbounded" minOccurs="0" name="params" type="tns:lbParameter"/> <xs:element minOccurs="0" name="condition" type="xs:string"/> <xs:element minOccurs="0" name="queryOption" type="tns:queryOption"/> </xs:sequence> </xs:complexType> <xs:complexType name="queryResponse"> <xs:sequence> <xs:element minOccurs="0" name="QueryResult" type="tns:queryResult"/> </xs:sequence> </xs:complexType> <xs:complexType name="update"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> <xs:element minOccurs="0" name="objectName" type="xs:string"/> <xs:element minOccurs="0" name="id" type="xs:string"/> <xs:element maxOccurs="unbounded" minOccurs="0" name="params" type="tns:lbParameter"/> </xs:sequence> </xs:complexType> <xs:complexType name="updateResponse"> <xs:sequence> <xs:element minOccurs="0" name="LBEResult" type="tns:lbeResult"/> </xs:sequence> </xs:complexType> <xs:complexType name="execBizProcess"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> <xs:element minOccurs="0" name="bizProcessName" type="xs:string"/> <xs:element minOccurs="0" name="id" type="xs:string"/> <xs:element maxOccurs="unbounded" minOccurs="0" name="params" type="tns:lbParameter"/> <xs:element maxOccurs="unbounded" minOccurs="0" name="variables" type="tns:lbParameter"/> </xs:sequence> </xs:complexType> <xs:complexType name="execBizProcessResponse"> <xs:sequence> <xs:element minOccurs="0" name="BizProcessResult" type="tns:bizProcessResult"/> </xs:sequence> </xs:complexType> <xs:complexType name="bizProcessResult"> <xs:complexContent> <xs:extension base="tns:lbeResult"> <xs:sequence> <xs:element maxOccurs="unbounded" minOccurs="0" name="outputVariables" nillable="true" type="tns:lbParameter"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> <xs:complexType name="logout"> <xs:sequence> <xs:element minOccurs="0" name="sessionId" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="logoutResponse"> <xs:sequence> <xs:element minOccurs="0" name="LogoutResult" type="tns:logoutResult"/> </xs:sequence> </xs:complexType> <xs:complexType name="logoutResult"> <xs:complexContent> <xs:extension base="tns:lbeResult"> <xs:sequence/> </xs:extension> </xs:complexContent> </xs:complexType> <xs:simpleType name="valueOption"> <xs:restriction base="xs:string"> <xs:enumeration value="VALUE"/> <xs:enumeration value="DISPLAY"/> <xs:enumeration value="BOTH"/> </xs:restriction> </xs:simpleType> </xs:schema> </wsdl:types> <wsdl:message name="login"> <wsdl:part element="tns:login" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="queryWorkflowDescribeResponse"> <wsdl:part element="tns:queryWorkflowDescribeResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="createResponse"> <wsdl:part element="tns:createResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="delete"> <wsdl:part element="tns:delete" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="logoutResponse"> <wsdl:part element="tns:logoutResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="execBizProcessResponse"> <wsdl:part element="tns:execBizProcessResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="updateResponse"> <wsdl:part element="tns:updateResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="queryTasksResponse"> <wsdl:part element="tns:queryTasksResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="doWorkActionByObject"> <wsdl:part element="tns:doWorkActionByObject" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="doWorkActionByObjectResponse"> <wsdl:part element="tns:doWorkActionByObjectResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="update"> <wsdl:part element="tns:update" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="validateUser"> <wsdl:part element="tns:validateUser" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="queryTaskListByConditionResponse"> <wsdl:part element="tns:queryTaskListByConditionResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="query"> <wsdl:part element="tns:query" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="doWorkAction"> <wsdl:part element="tns:doWorkAction" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="getWorkOwnerResponse"> <wsdl:part element="tns:getWorkOwnerResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="queryWorkflowDescribe"> <wsdl:part element="tns:queryWorkflowDescribe" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="logout"> <wsdl:part element="tns:logout" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="deleteResponse"> <wsdl:part element="tns:deleteResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="getWorkAvailableAction"> <wsdl:part element="tns:getWorkAvailableAction" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="queryTaskListByCondition"> <wsdl:part element="tns:queryTaskListByCondition" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="validateUserResponse"> <wsdl:part element="tns:validateUserResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="queryTasks"> <wsdl:part element="tns:queryTasks" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="queryResponse"> <wsdl:part element="tns:queryResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="getUserInfo"> <wsdl:part element="tns:getUserInfo" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="doWorkActionResponse"> <wsdl:part element="tns:doWorkActionResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="getWorkOwner"> <wsdl:part element="tns:getWorkOwner" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="create"> <wsdl:part element="tns:create" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="execBizProcess"> <wsdl:part element="tns:execBizProcess" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="getUserInfoResponse"> <wsdl:part element="tns:getUserInfoResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="getWorkAvailableActionResponse"> <wsdl:part element="tns:getWorkAvailableActionResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:message name="loginResponse"> <wsdl:part element="tns:loginResponse" name="parameters"></wsdl:part> </wsdl:message> <wsdl:portType name="LBEBusinessService"> <wsdl:operation name="getWorkAvailableAction"> <wsdl:input message="tns:getWorkAvailableAction" name="getWorkAvailableAction"></wsdl:input> <wsdl:output message="tns:getWorkAvailableActionResponse" name="getWorkAvailableActionResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="queryTasks"> <wsdl:input message="tns:queryTasks" name="queryTasks"></wsdl:input> <wsdl:output message="tns:queryTasksResponse" name="queryTasksResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="queryWorkflowDescribe"> <wsdl:input message="tns:queryWorkflowDescribe" name="queryWorkflowDescribe"></wsdl:input> <wsdl:output message="tns:queryWorkflowDescribeResponse" name="queryWorkflowDescribeResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="getWorkOwner"> <wsdl:input message="tns:getWorkOwner" name="getWorkOwner"></wsdl:input> <wsdl:output message="tns:getWorkOwnerResponse" name="getWorkOwnerResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="doWorkActionByObject"> <wsdl:input message="tns:doWorkActionByObject" name="doWorkActionByObject"></wsdl:input> <wsdl:output message="tns:doWorkActionByObjectResponse" name="doWorkActionByObjectResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="getUserInfo"> <wsdl:input message="tns:getUserInfo" name="getUserInfo"></wsdl:input> <wsdl:output message="tns:getUserInfoResponse" name="getUserInfoResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="create"> <wsdl:input message="tns:create" name="create"></wsdl:input> <wsdl:output message="tns:createResponse" name="createResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="doWorkAction"> <wsdl:input message="tns:doWorkAction" name="doWorkAction"></wsdl:input> <wsdl:output message="tns:doWorkActionResponse" name="doWorkActionResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="delete"> <wsdl:input message="tns:delete" name="delete"></wsdl:input> <wsdl:output message="tns:deleteResponse" name="deleteResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="login"> <wsdl:input message="tns:login" name="login"></wsdl:input> <wsdl:output message="tns:loginResponse" name="loginResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="validateUser"> <wsdl:input message="tns:validateUser" name="validateUser"></wsdl:input> <wsdl:output message="tns:validateUserResponse" name="validateUserResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="queryTaskListByCondition"> <wsdl:input message="tns:queryTaskListByCondition" name="queryTaskListByCondition"></wsdl:input> <wsdl:output message="tns:queryTaskListByConditionResponse" name="queryTaskListByConditionResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="query"> <wsdl:input message="tns:query" name="query"></wsdl:input> <wsdl:output message="tns:queryResponse" name="queryResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="update"> <wsdl:input message="tns:update" name="update"></wsdl:input> <wsdl:output message="tns:updateResponse" name="updateResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="execBizProcess"> <wsdl:input message="tns:execBizProcess" name="execBizProcess"></wsdl:input> <wsdl:output message="tns:execBizProcessResponse" name="execBizProcessResponse"></wsdl:output> </wsdl:operation> <wsdl:operation name="logout"> <wsdl:input message="tns:logout" name="logout"></wsdl:input> <wsdl:output message="tns:logoutResponse" name="logoutResponse"></wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="LBEBusinessWebServiceSoapBinding" type="tns:LBEBusinessService"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="getWorkAvailableAction"> <soap:operation soapAction="" style="document"/> <wsdl:input name="getWorkAvailableAction"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="getWorkAvailableActionResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="queryTasks"> <soap:operation soapAction="" style="document"/> <wsdl:input name="queryTasks"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="queryTasksResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="queryWorkflowDescribe"> <soap:operation soapAction="" style="document"/> <wsdl:input name="queryWorkflowDescribe"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="queryWorkflowDescribeResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="getWorkOwner"> <soap:operation soapAction="" style="document"/> <wsdl:input name="getWorkOwner"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="getWorkOwnerResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="doWorkActionByObject"> <soap:operation soapAction="" style="document"/> <wsdl:input name="doWorkActionByObject"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="doWorkActionByObjectResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="getUserInfo"> <soap:operation soapAction="" style="document"/> <wsdl:input name="getUserInfo"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="getUserInfoResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="create"> <soap:operation soapAction="" style="document"/> <wsdl:input name="create"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="createResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="delete"> <soap:operation soapAction="" style="document"/> <wsdl:input name="delete"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="deleteResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="doWorkAction"> <soap:operation soapAction="" style="document"/> <wsdl:input name="doWorkAction"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="doWorkActionResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="login"> <soap:operation soapAction="" style="document"/> <wsdl:input name="login"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="loginResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="validateUser"> <soap:operation soapAction="" style="document"/> <wsdl:input name="validateUser"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="validateUserResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="queryTaskListByCondition"> <soap:operation soapAction="" style="document"/> <wsdl:input name="queryTaskListByCondition"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="queryTaskListByConditionResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="query"> <soap:operation soapAction="" style="document"/> <wsdl:input name="query"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="queryResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="update"> <soap:operation soapAction="" style="document"/> <wsdl:input name="update"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="updateResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="execBizProcess"> <soap:operation soapAction="" style="document"/> <wsdl:input name="execBizProcess"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="execBizProcessResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> <wsdl:operation name="logout"> <soap:operation soapAction="" style="document"/> <wsdl:input name="logout"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="logoutResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="LBEBusinessWebService"> <wsdl:port binding="tns:LBEBusinessWebServiceSoapBinding" name="LBEBusinessServiceImplPort"> <soap:address location="http://hi-ray.vicp.cc:8099/service/LBEBusiness"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
它在pc上可以正常运行,但是我把它放在PDA(移动设备)中就得到不到正确的对象,登录不成功无法在PDA中使用。我做的目的就是放在移动设备上扫描条码使用的。上面截图是我把项目直接部署在设备上进行调试的。
@忽而今夏: 这就好办了,你对比下这两者自动生成的代码的差异。
@Launcher:
在windows 项目和智能设备项目中分别引用这个webservice,生成的Reference代理类肯定是不一样的。
毕竟.net cf只是.net的精简版,里面有很多内容都没有。在windows代理类中每个方法都会有Async后缀的方法,但在智能设备项目中这没有这类方法的。
我还想请教一个问题,web方法中需要一个类数组,我该怎么拼接soap报文,比如query方法:有一个lbParameter类型的数组params参数,上面有说明,请问我该params参数转换为字符串还其它的,放在报文中呢?
@忽而今夏: 我不是要你比较 Async 这些,而是比较 loginResult 这些类的定义,包括代理类的基类。你的 .net 版能正常调用,用 Fiddler 抓个包,你就能看到数组参数序列化后的 SOAP 格式。
wince 不能生成使用 wcf 的服务代理吗?
@Launcher: 非常感谢你的回答,目前程序可以在PDA中正常运行,
Fiddler这个工具非常棒,直接运行就可以截取http连接发送或接收的报文信息,如果是类型数组,它会写成多个类型节点:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <execBizProcess xmlns="http://ws.livebos.apex.com/"> <sessionId xmlns="">236fab3eb42828e54db062a44c9845c7</sessionId> <bizProcessName xmlns="">tUser_M2</bizProcessName> <id xmlns="" /> <params xmlns=""> <name>userid</name><value>zhangsan</value> </params> <params xmlns=""> <name>password</name><value>123</value> </params> </execBizProcess> </soap:Body> </soap:Envelope>
报文中的params就是一个lbParameter类型的数组所转换成的。
我把所有用到的方法都使用发送的soap报文的方式来使用,并注释代理类中的类的特性,然后程序就可以在PDA中运行了。
智能设备中好像没有添加wcf服务的界面,它就一个引用web服务界面!