我正在使用Web服务根据特殊的公司编号来呈现公司信息。
但是我无法从响应SOAP消息中获取数据。
您可以看到响应消息的示例。 (我省略了一些公司信息标签)。

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<businessGetDossierV3Response xmlns="http://www.webservices.nl/soap/">
<out>
<paging>
<curpage>1</curpage>
<perpage>10</perpage>
<numpages>1</numpages>
<numresults>1</numresults>
<maxresults>100</maxresults>
</paging>
<results>
<item>
<DossierNo></DossierNo>
<SubDossierNo></SubDossierNo>
<ChamberNo></ChamberNo>
<Legalformcode></Legalformcode>
<LegalformcodeText></LegalformcodeText>
<Tradename45></Tradename45>
<EstablishmentPostcode></EstablishmentPostcode>
<EstablishmentCity></EstablishmentCity>
<EstablishmentStreetname></EstablishmentStreetname>
<EstablishmentHouseNo></EstablishmentHouseNo>
<CorrespondencePostcode></CorrespondencePostcode>
<CorrespondenceCity></CorrespondenceCity>
<CorrespondenceStreetname></CorrespondenceStreetname>
<CorrespondenceHouseNo></CorrespondenceHouseNo>
</item>
</results>
</out>
</businessGetDossierV3Response>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


!这是我在演示客户端上看到的结果!
但这是我在C#中的代码

        nl.webservices.ws1.BusinessDossierV3PagedResult result = null;
        result = myserviceBusiness.businessGetDossierV3(KVKnr, "0000", 1);


我想做这样的事情(但要有结果而不是分页部分)

int page = result.paging.numpages;


那我应该是这样的

string city = result.results.item.CorrespondenceCity;


但这给出了错误信息

因此,在Visual Studio 2010中,我只能在xml的分页部分中检索数据并将其放入文本框,而不能从结果部分中检索。这是因为结果部分是某种Collection吗?

因此,是的,如何将来自标签EstablishmentPostcode和EstablishmentCity的数据放在默认页面的文本框中?

提前致谢

最佳答案

您可以尝试将SOAP服务添加为对该项目的Web参考。 http://msdn.microsoft.com/en-us/library/tydxdyw9.aspx

如果您不想这样做,而是直接在XML上工作,则可以使用xpath来访问results元素中的所有item元素。
http://www.stardeveloper.com/articles/display.html?article=2009031001&page=1

使用xpath时要注意的一件事是,对要选择的节点使用正确的xml名称空间。

关于c# - 如何从SOAP消息中检索集合,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5002424/

10-08 22:46