首页 新闻 会员 周边

【求助】.net1.1调用webservice返回二维数组时提示“XML 文档(1, 378)中有错

1
悬赏园豆:20 [已解决问题] 解决于 2010-09-02 09:58

具体描述请访问地:http://www.cnblogs.com/dreamof/archive/2010/08/31/1813534.html

  最近,由于业务需求,项目需要调用其他单位提供的接口来同步数据,对方提供的接口是java开发的WebService,返回的数据是二维数组。我们的项目是05年开发的.net1.1版本,在调用对方接口获取返回的二维数组数据时,提示“XML 文档(1, 378)中有错误”。经测试无论在哪个框架下添加引用对方服务时,生成的CS文件返回的都是一维数组,而并非二维数组,在.net2.0以上版本,强制性修改CS文件的方法来返回二维数组可以得到对方的数据,但在.net1.1版本,强制性修改CS文件的方法来返回二维数组时就提示“XML 文档(1, 378)中有错误”。上google搜索该问题,部分网友说.net1.1调用WebService不支持二维数组,不知道是否真是这样,如果支持二维数组,请问各位园友这个问题如何解决?期待园友的解答,谢谢!


具体描述请访问地址:http://www.cnblogs.com/dreamof/archive/2010/08/31/1813534.html

 

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://register.webservice.hnisi.com.cn" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://register.webservice.hnisi.com.cn" xmlns:intf="http://register.webservice.hnisi.com.cn" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr
22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema targetNamespace="http://register.webservice.hnisi.com.cn" xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="ArrayOfString2D">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[][]"/>
</restriction>
</complexContent>
</complexType>
</schema>
</wsdl:types>

<wsdl:message name="registerRequest">

<wsdl:part name="userID" type="soapenc:string"/>

<wsdl:part name="password" type="soapenc:string"/>

<wsdl:part name="citizenInfos" type="impl:ArrayOfString2D"/>

</wsdl:message>

<wsdl:message name="findRegisterQuotaResponse">

<wsdl:part name="FindRegisterQuotaReturn" type="impl:ArrayOfString2D"/>

</wsdl:message>

<wsdl:message name="findRegisterQuotaRequest">

<wsdl:part name="userID" type="soapenc:string"/>

<wsdl:part name="password" type="soapenc:string"/>

<wsdl:part name="annual" type="soapenc:string"/>

<wsdl:part name="departmentCode" type="soapenc:string"/>

</wsdl:message>

<wsdl:message name="registerResponse">

<wsdl:part name="RegisterReturn" type="impl:ArrayOfString2D"/>

</wsdl:message>

<wsdl:portType name="RegisterService">

<wsdl:operation name="register" parameterOrder="userID password citizenInfos">

<wsdl:input message="impl:registerRequest" name="registerRequest"/>

<wsdl:output message="impl:registerResponse" name="registerResponse"/>

</wsdl:operation>

<wsdl:operation name="findRegisterQuota" parameterOrder="userID password annual departmentCode">

<wsdl:input message="impl:findRegisterQuotaRequest" name="findRegisterQuotaRequest"/>

<wsdl:output message="impl:findRegisterQuotaResponse" name="findRegisterQuotaResponse"/>

</wsdl:operation>

</wsdl:portType>

<wsdl:binding name="RegisterServiceSoapBinding" type="impl:RegisterService">

<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

<wsdl:operation name="register">

<wsdlsoap:operation soapAction=""/>

<wsdl:input name="registerRequest">

<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://register.webservice.hnisi.com.cn" use="encoded"/>

</wsdl:input>

<wsdl:output name="registerResponse">

<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://register.webservice.hnisi.com.cn" use="encoded"/>

</wsdl:output>

</wsdl:operation>

<wsdl:operation name="findRegisterQuota">

<wsdlsoap:operation soapAction=""/>

<wsdl:input name="findRegisterQuotaRequest">

<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://register.webservice.hnisi.com.cn" use="encoded"/>

</wsdl:input>

<wsdl:output name="findRegisterQuotaResponse">

<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://register.webservice.hnisi.com.cn" use="encoded"/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

<wsdl:service name="RegisterService">

<wsdl:port binding="impl:RegisterServiceSoapBinding" name="RegisterService">

<wsdlsoap:address location="http://172.16.70.40:7001/rhsh/services/RegisterService"/>

</wsdl:port>

</wsdl:service>

</wsdl:definitions>

 

 修改后的代码如下:

//string uri = "http://172.16.70.40:7001/rhsh/services/RegisterService"; //修改前,原因:此地址无法访问
string uri = "http://172.16.70.40:7001/rhsh/services/RegisterService?wsdl"; //修改后
HttpWebRequest hwRequest = (HttpWebRequest)WebRequest.Create(uri);
// 下面这些的参数,以及不包括在这里的参数,也就是
// HTTP Headers 中包含的参数的具体值需要根据对方
// 服务器的设置而定。
hwRequest.Method = "POST";
hwRequest.ContentType
= "text/xml;charset=UTF-8";
hwRequest.Headers.Add(
"SOAPAction", "*"); // 不知道,假装不知道。
hwRequest.UserAgent = "Jakarta Commons-HttpClient/3.1";
//hwRequest.Host = "register.webservice.hnisi.com.cn"; //没有Host的属性
hwRequest.Timeout = 1000 * 60 * 3;
hwRequest.KeepAlive
= false;
// 对方是 Apache
hwRequest.ServicePoint.Expect100Continue = false;
// 从 FindRegisterRequest.xml 读取请求数据。
// 因为我们需要修改请求中的一些参数,也就是输入参数,
// 因此,我们使用 XmlDocument 来简化操作。
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(
"RegisterService.xml"); //报错,提示找不到文件RegisterService.xml
XmlNode userIDNode = xmlDoc.GetElementsByTagName("userID")[0];
userIDNode.InnerText
= "test1";
XmlNode pwdNode
= xmlDoc.GetElementsByTagName("password")[0];
pwdNode.InnerText
= "2222";
XmlNode annualNode
= xmlDoc.GetElementsByTagName("annual")[0];
annualNode.InnerText
= "2010";
XmlNode depCodeNode
= xmlDoc.GetElementsByTagName("departmentCode")[0];
depCodeNode.InnerText
= "S44010300";
byte[] sendBuffer = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
hwRequest.ContentLength
= sendBuffer.Length;
// 写 POST 数据
using (Stream reqStream = hwRequest.GetRequestStream())
reqStream.Write(sendBuffer,
0, sendBuffer.Length);
// 接受响应
HttpWebResponse hwResponse = (HttpWebResponse)hwRequest.GetResponse();
try
{
using (Stream resStream = hwResponse.GetResponseStream())
{
using (StreamReader sr = new StreamReader(resStream))
{
// 如果上面都没有出错的话,这里就读到结果了,
// 我只是简单的转换成 string,就是方便查看,
// 如果确切的知道响应的 SOAP 格式,就可以读取出来。
string xmlText = sr.ReadToEnd();
}
}
}
finally
{
hwResponse.Close();
}

 得到的XML数据如下:

<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope 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\">
<soapenv:Body>
<ns1:findRegisterQuotaResponse soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns1=\"http://register.webservice.hnisi.com.cn\">
<FindRegisterQuotaReturn soapenc:arrayType=\"soapenc:string[][3]\" xsi:type=\"soapenc:Array\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">
<FindRegisterQuotaReturn soapenc:arrayType=\"soapenc:string[12]\" xsi:type=\"soapenc:Array\">
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">ID</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">YEAR</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">KIND</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">TOTAL</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">BEGINNUMBER</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">ENDNUMBER</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">CURRENTPOINTER</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">BEGINTIME</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">ENDTIME</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">USINGDEPT</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">YRDW</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">ZY</FindRegisterQuotaReturn>
</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn soapenc:arrayType=\"soapenc:string[12]\" xsi:type=\"soapenc:Array\">
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">RHSH440120100512006766</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">2010</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">20</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">50000</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">1</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">50000</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">1</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">20100512000000</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">20110101000000</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">S44010300</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\" xsi:nil=\"true\"/>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\" xsi:nil=\"true\"/>
</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn soapenc:arrayType=\"soapenc:string[12]\" xsi:type=\"soapenc:Array\">
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">RHSH440120100512006763</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">2010</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">10</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">50000</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">20001</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">70000</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">20002</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">20100512000000</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">20110101000000</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\">S44010300</FindRegisterQuotaReturn>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\" xsi:nil=\"true\"/>
<FindRegisterQuotaReturn xsi:type=\"soapenc:string\" xsi:nil=\"true\"/>
</FindRegisterQuotaReturn>
</FindRegisterQuotaReturn>
</ns1:findRegisterQuotaResponse>
</soapenv:Body>
</soapenv:Envelope>"

 

最终代码和数据如下:

string uri = "http://172.16.70.40:7001/rhsh/services/RegisterService?wsdl";
HttpWebRequest hwRequest
= (HttpWebRequest)WebRequest.Create(uri);
// 下面这些的参数,以及不包括在这里的参数,也就是
// HTTP Headers 中包含的参数的具体值需要根据对方
// 服务器的设置而定。
hwRequest.Method = "POST";
hwRequest.ContentType
= "text/xml;charset=UTF-8";
hwRequest.Headers.Add(
"SOAPAction", "*");
hwRequest.UserAgent
= "Jakarta Commons-HttpClient/3.1";
hwRequest.Timeout
= 1000 * 60 * 3;
hwRequest.KeepAlive
= false;
// 对方是 Apache
hwRequest.ServicePoint.Expect100Continue = false;
// 从 FindRegisterRequest.xml 读取请求数据。
// 因为我们需要修改请求中的一些参数,也就是输入参数,
// 因此,我们使用 XmlDocument 来简化操作。
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(
"RegisterService.xml");
XmlNode userIDNode
= xmlDoc.GetElementsByTagName("userID")[0];
userIDNode.InnerText
= "test1";
XmlNode pwdNode
= xmlDoc.GetElementsByTagName("password")[0];
pwdNode.InnerText
= "2222";
XmlNode annualNode
= xmlDoc.GetElementsByTagName("annual")[0];
annualNode.InnerText
= "2010";
XmlNode depCodeNode
= xmlDoc.GetElementsByTagName("departmentCode")[0];
depCodeNode.InnerText
= "S44010300";
byte[] sendBuffer = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
hwRequest.ContentLength
= sendBuffer.Length;
// 写 POST 数据
using (Stream reqStream = hwRequest.GetRequestStream())
reqStream.Write(sendBuffer,
0, sendBuffer.Length);
// 接受响应
HttpWebResponse hwResponse = (HttpWebResponse)hwRequest.GetResponse();
try
{
using (Stream resStream = hwResponse.GetResponseStream())
{
using (StreamReader sr = new StreamReader(resStream))
{
// 如果上面都没有出错的话,这里就读到结果了,
// 我只是简单的转换成 string,就是方便查看,
// 如果确切的知道响应的 SOAP 格式,就可以读取出来。
string xmlText = sr.ReadToEnd();
XmlDocument xdDoc
= new XmlDocument();
xdDoc.LoadXml(xmlText);
XmlNode quotaResponse
= xdDoc.DocumentElement.FirstChild.FirstChild;
if (!quotaResponse.HasChildNodes || quotaResponse == null)
return;
XmlNode quotaReturn
= quotaResponse.FirstChild;
if (!quotaReturn.HasChildNodes || quotaReturn == null)
return;
string[][] array = new string[quotaReturn.ChildNodes.Count][];
for (int i = 0, j = array.Length; i < j; i++)
{
XmlNodeList nodes
= quotaReturn.ChildNodes[i].ChildNodes;
array[i]
= new string[nodes.Count];
for (int m = 0, n = array[i].Length; m < n; m++)
{
array[i][m]
= nodes[m].InnerText;
}
}

Response.Write(
"<table border=\"1\">");
for (int i = 0; i < array.Length; i++)
{
Response.Write(
"<tr>");
string[] a = array[i];
for (int j = 0; j < a.Length; j++)
{
Response.Write(
"<td>" + Convert.ToString(a[j]) + "&nbsp;</td>");
}
Response.Write(
"</tr>");
}
Response.Write(
"</table>");
}
}
}
finally
{
hwResponse.Close();
}

飛雪飄寒的主页 飛雪飄寒 | 初学一级 | 园豆:30
提问于:2010-08-31 14:15
< >
分享
最佳答案
0

你有测试用的服务地址吗?

反正,手动修改代码是可以成功的,就是把接口定义为返回 string .

 

没找到免费的,这里凑合着用吧!

 

string uri = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx";

HttpWebRequest hwRequest
= (HttpWebRequest)WebRequest.Create(uri);

// 下面这些的参数,以及不包括在这里的参数,也就是
// HTTP Headers 中包含的参数的具体值需要根据对方
// 服务器的设置而定。
hwRequest.Method = "POST";
hwRequest.ContentType
= "text/xml; charset=utf-8";
hwRequest.Headers.Add(
"SOAPAction", "http://WebXml.com.cn/getWeather");
hwRequest.UserAgent
= "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
hwRequest.Host
= "webservice.webxml.com.cn";
hwRequest.Timeout
= 1000 * 60 * 3;

// 从 GetWeatherRequest.xml 读取请求数据。
// 因为我们需要修改请求中的一些参数,也就是输入参数,
// 因此,我们使用 XmlDocument 来简化操作。
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(
"GetWeatherRequest.xml");

XmlNode cityCodeNode
=xmlDoc.GetElementsByTagName("theCityCode")[0];
cityCodeNode.InnerText
= "北京";

XmlNode userIDNode
= xmlDoc.GetElementsByTagName("theUserID")[0];
userIDNode.InnerText
= "没有用户名";

byte[] sendBuffer = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
hwRequest.ContentLength
= sendBuffer.Length;

// 写 POST 数据
using(Stream reqStream = hwRequest.GetRequestStream())
reqStream.Write(sendBuffer,
0, sendBuffer.Length);

// 接受响应
HttpWebResponse hwResponse = (HttpWebResponse)hwRequest.GetResponse();
try
{
using (Stream resStream = hwResponse.GetResponseStream())
{
using (StreamReader sr = new StreamReader(resStream))
{
// 如果上面都没有出错的话,这里就读到结果了,
// 我只是简单的转换成 string,就是方便查看,
// 如果确切的知道响应的 SOAP 格式,就可以读取出来。
string xmlText = sr.ReadToEnd();
}
}
}
finally
{
hwResponse.Close();
}

 

GetWeatherRequest.xml 的定义如下:

 

<?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:Body>
<getWeather xmlns="http://WebXml.com.cn/">
<theCityCode>string</theCityCode>
<theUserID>string</theUserID>
</getWeather>
</soap:Body>
</soap:Envelope>

 

 

根据你的WSDL修改,有些Header拿不准,你最好抓个包,以确定具体的值

 

string uri = "http://172.16.70.40:7001/rhsh/services/RegisterService";

HttpWebRequest hwRequest
= (HttpWebRequest)WebRequest.Create(uri);

// 下面这些的参数,以及不包括在这里的参数,也就是
// HTTP Headers 中包含的参数的具体值需要根据对方
// 服务器的设置而定。
hwRequest.Method = "POST";
hwRequest.ContentType
= "text/xml;charset=UTF-8";
hwRequest.Headers.Add(
"SOAPAction", "*"); // 不知道,假装不知道。
hwRequest.UserAgent = "Jakarta Commons-HttpClient/3.1";
hwRequest.Host
= "register.webservice.hnisi.com.cn";
hwRequest.Timeout
= 1000 * 60 * 3;
hwRequest.KeepAlive
= false;

// 对方是 Apache
hwRequest.ServicePoint.Expect100Continue = false;

// 从 FindRegisterRequest.xml 读取请求数据。
// 因为我们需要修改请求中的一些参数,也就是输入参数,
// 因此,我们使用 XmlDocument 来简化操作。
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(
"FindRegisterRequest.xml");

XmlNode userIDNode
= xmlDoc.GetElementsByTagName("userID")[0];
userIDNode.InnerText
= "不知道是啥用户名";

XmlNode pwdNode
= xmlDoc.GetElementsByTagName("password")[0];
pwdNode.InnerText
= "更不知道密码";

XmlNode annualNode
= xmlDoc.GetElementsByTagName("annual")[0];
annualNode.InnerText
= "这是个啥东西?";

XmlNode depCodeNode
= xmlDoc.GetElementsByTagName("departmentCode")[0];
depCodeNode.InnerText
= "那个部门?";

byte[] sendBuffer = Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
hwRequest.ContentLength
= sendBuffer.Length;

// 写 POST 数据
using (Stream reqStream = hwRequest.GetRequestStream())
reqStream.Write(sendBuffer,
0, sendBuffer.Length);

// 接受响应
HttpWebResponse hwResponse = (HttpWebResponse)hwRequest.GetResponse();
try
{
using (Stream resStream = hwResponse.GetResponseStream())
{
using (StreamReader sr = new StreamReader(resStream))
{
// 如果上面都没有出错的话,这里就读到结果了,
// 我只是简单的转换成 string,就是方便查看,
// 如果确切的知道响应的 SOAP 格式,就可以读取出来。
string xmlText = sr.ReadToEnd();
}
}
}
finally
{
hwResponse.Close();
}

 

请求消息格式文件:

 

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:reg="http://register.webservice.hnisi.com.cn">
<soapenv:Header/>
<soapenv:Body>
<reg:findRegisterQuota soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<userID xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</userID>
<password xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</password>
<annual xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</annual>
<departmentCode xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</departmentCode>
</reg:findRegisterQuota>
</soapenv:Body>
</soapenv:Envelope>

 

在将响应读成字符串后,用下面方法创建string 数组,在原来代码这句之后             string xmlText = sr.ReadToEnd();                   

 

XmlDocument xdDoc = new XmlDocument();
xdDoc.LoadXml(xmlText);

XmlNode quotaResponse
= xdDoc.DocumentElement.FirstChild.FirstChild;
if (!quotaResponse.HasChildNodes || quotaResponse == null)
return;

XmlNode quotaReturn
= quotaResponse.FirstChild;
if (!quotaReturn.HasChildNodes || quotaReturn == null)
return;

string[][] array = new string[quotaReturn.ChildNodes.Count][];
for (int i = 0, j = array.Count(); i < j; i++)
{
XmlNodeList nodes
= quotaReturn.ChildNodes[i].ChildNodes;
array[i]
= new string[nodes.Count];

for (int m = 0, n = array[i].Count(); m < n; m++)
{
array[i][m]
= nodes[m].InnerText;
}
}
收获园豆:20
Launcher | 高人七级 |园豆:45045 | 2010-08-31 14:28
谢谢你的回答,按照你的方法刚测试过了,提示一样的错误,看来这种方法行不起呀!
飛雪飄寒 | 园豆:30 (初学一级) | 2010-08-31 14:37
@飛雪飄寒:我的意思是用HttpWebRequest,post数据,然后自己读soap xml,不使用System.Xml.Serialization.SoapElementAttribute. 你有Fiddler吗?可否抓个包给看看.
Launcher | 园豆:45045 (高人七级) | 2010-08-31 14:51
不明白你的意思,能否详细说明一下,我再试试!
飛雪飄寒 | 园豆:30 (初学一级) | 2010-08-31 15:06
@飛雪飄寒: HttpWebRequest request = (HttpWebRequest)WebRequest.Create("服务地址"); request.Method = "POST"; 还有些其它参数,你回头抓了包,我们再填写; 我假设你已经写好了Body的数据,按照soap格式写的xml字符串为 sendMessage byte[] data = Encoding.GetEncoding("UTF-8").GetBytes(sendMessage); request.ContentLength = data.Length; //写POST数据 Stream requestStream = request.GetRequestStream(); requestStream.Write(data, 0, data.Length); //接收返回数据 HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream recvMessage = response.GetResponseStream(); 这个 recvMessage 流中就保存了响应结果,可以使用 XmlTextReader 来读去它.
Launcher | 园豆:45045 (高人七级) | 2010-08-31 15:38
@Galactica: 之前没用过这种方法,能否给份样例给我看看,谢谢!
飛雪飄寒 | 园豆:30 (初学一级) | 2010-09-01 10:50
@飛雪飄寒:你等我找一个 aol 免费的web servcie 再给你代码
Launcher | 园豆:45045 (高人七级) | 2010-09-01 11:05
@飛雪飄寒:给你更新了个http post soap 的例子.
Launcher | 园豆:45045 (高人七级) | 2010-09-01 13:08
@Galactica: 谢谢你,你真是个热心人。 上面的示例我测试过了,还是不行,我把对方的服务内容全部截图,放到问题补充那了,麻烦你再帮忙看看。
飛雪飄寒 | 园豆:30 (初学一级) | 2010-09-01 15:18
@飛雪飄寒:你把生成的wsdl文件给我,别给我截图,看着图,我还得一个一个敲字母,麻烦. 你出错就两个原因:1,没按照对方的接口写对 xxxRequest.xml 文件中的内容;2,对方使用的服务器,不支持 Expect100Continue 等参数,你没根据实际情况去设置相关的HTTP Header.
Launcher | 园豆:45045 (高人七级) | 2010-09-01 15:44
@Galactica: OK,我把内容全部贴出来给你看。
飛雪飄寒 | 园豆:30 (初学一级) | 2010-09-01 15:49
@飛雪飄寒:给你更新了答案,出错后,记得把详细错误信息保存下来.
Launcher | 园豆:45045 (高人七级) | 2010-09-01 16:22
@Galactica: 有部分地方报错,我做了修改,具体请看问题描述那的最新代码。
飛雪飄寒 | 园豆:30 (初学一级) | 2010-09-01 17:44
@Galactica: 有几处地方报错,具体错误请看问题描述中的代码中的红色字体!
飛雪飄寒 | 园豆:30 (初学一级) | 2010-09-01 17:56
@飛雪飄寒:没有host没关系,可以不加,如果非要加(比如不加就请求失败),就这样: hwRequest.Headers.Add("Host", "register.webservice.hnisi.com.cn"); FindRegisterRequest.xml 这个文件就我在代码后面给你的请求的消息格式,你自己新建一个xml文件,然后把我再代码后面给你的请求消息内容复制进去,把新建的xml文件的内容都覆盖掉,然后你可以在xml文件属性里设置"复制到输出目录"设置为"如果较新则复制",或者你自己放一个目录,只要能读到就行了.
Launcher | 园豆:45045 (高人七级) | 2010-09-01 18:07
@Galactica: 谢谢,你真是太有才了,按照你的方法已经得到了XML数据,我已经把得到的XML数据放在问题描述处了,请问如何调用服务来获取这些数据呢?
飛雪飄寒 | 园豆:30 (初学一级) | 2010-09-01 18:47
@飛雪飄寒:给你更新答案了,其实也可以直接从resStream创建 XmlDocument.
Launcher | 园豆:45045 (高人七级) | 2010-09-01 20:38
@Galactica: 谢谢你,按照你的方法可以得到数据了,最终代码及数据已放到问题描述处了。
飛雪飄寒 | 园豆:30 (初学一级) | 2010-09-02 09:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册