我在从Visual Studio 2010 C#项目访问SOAP服务时遇到问题。我已经完成了以下步骤:
但是当我在项目中构建响应对象时,我收到了一个错误:
XML文档中存在错误(1,401)。无法识别指定的类型:name =':DataField',namespace ='',at< return xmlns =''>。
似乎构建Array对象时出现问题。响应XML看起来很好......来自Fiddler:
HTTP/1.1 200 OK
Date: Tue, 24 Jan 2012 09:58:40 GMT
Server: Apache/2.2.16 (Win32) mod_ssl/2.2.16 OpenSSL/0.9.8o
X-Powered-By: PHP/5.3.5 ZendServer
Set-Cookie: PHPSESSID=xxxxxxxxxxxxxxxxxxxxxxxxxxx; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
X-SOAP-Server: NuSOAP/0.9.5 (1.123)
Content-Length: 2055
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/xml; charset=UTF-8
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 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" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:getDataFieldsResponse xmlns:ns1="tns">
<return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType=":DataField[12]">
<item xsi:type=":DataField">
<name xsi:type="xsd:string">Windgeschwindigkeit</name>
<ident xsi:type="xsd:string">1002</ident>
</item>
<item xsi:type=":DataField">
<name xsi:type="xsd:string">Windgeschwindigkeit Max</name>
<ident xsi:type="xsd:string">1003</ident>
</item>
<item xsi:type=":DataField">
<name xsi:type="xsd:string">Windgeschwindigkeit Min</name>
<ident xsi:type="xsd:string">1004</ident>
</item>
<item xsi:type=":DataField">
<name xsi:type="xsd:string">Rotordrehzahl</name>
<ident xsi:type="xsd:string">1005</ident>
</item>
<item xsi:type=":DataField">
<name xsi:type="xsd:string">Rotordrehzahl Max</name>
<ident xsi:type="xsd:string">1006</ident>
</item>
<item xsi:type=":DataField">
<name xsi:type="xsd:string">Rotordrehzahl Min</name>
<ident xsi:type="xsd:string">1007</ident>
</item>
<item xsi:type=":DataField">
<name xsi:type="xsd:string">Leistung</name>
<ident xsi:type="xsd:string">1008</ident>
</item>
<item xsi:type=":DataField">
<name xsi:type="xsd:string">Leistung Max</name>
<ident xsi:type="xsd:string">1009</ident>
</item>
<item xsi:type=":DataField">
<name xsi:type="xsd:string">Leistung Min</name>
<ident xsi:type="xsd:string">1010</ident>
</item>
<item xsi:type=":DataField">
<name xsi:type="xsd:string">Windrichtung</name>
<ident xsi:type="xsd:string">1012</ident>
</item>
<item xsi:type=":DataField">
<name xsi:type="xsd:string">Generator Umdr.</name>
<ident xsi:type="xsd:string">1013</ident>
</item>
<item xsi:type=":DataField">
<name xsi:type="xsd:string">Stop Fault</name>
<ident xsi:type="xsd:string">1014</ident>
</item>
</return>
</ns1:getDataFieldsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
但我似乎无法获得构建的响应对象。我是否必须手动尝试解析此XML?这将是一项很多工作,因为我需要使用的服务有许多不同的方法......
还有其他建议吗?
WSDL的第一行如下所示:
<definitions targetNamespace="http://wpr.rotorsoft.net/soap/ROTORsoftService">
<types>
<xsd:schema targetNamespace="http://wpr.rotorsoft.net/soap/ROTORsoftService">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
<xsd:complexType name="DataClass">
<xsd:all>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="ident" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="DataClassArray">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:DataClass[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="DataField">
<xsd:all>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="ident" type="xsd:string"/>
<xsd:element name="value" type="xsd:string"/>
<xsd:element name="timestamp" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="DataFieldArray">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:DataField[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="PowerUnit">
<xsd:all>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="ident" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="PowerUnitArray">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:PowerUnit[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="DataRecord">
<xsd:all>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="timestamp" type="xsd:string"/>
<xsd:element name="msec" type="xsd:string"/>
<xsd:element name="original" type="xsd:int"/>
<xsd:element name="fields" type="tns:DataFieldArray"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="DataRecordArray">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:DataRecord[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="DataPart">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:DataRecord[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="InfoPart">
<xsd:all>
<xsd:element name="powerunit" type="tns:PowerUnit"/>
<xsd:element name="dataclass" type="tns:DataClass"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="GetDataFormat">
<xsd:all>
<xsd:element name="info" type="tns:InfoPart"/>
<xsd:element name="data" type="tns:DataPart"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="PULogEntry">
<xsd:all>
<xsd:element name="begin" type="xsd:string"/>
<xsd:element name="end" type="xsd:string"/>
<xsd:element name="duration" type="xsd:string"/>
<xsd:element name="error" type="xsd:string"/>
<xsd:element name="errgroup" type="xsd:string"/>
<xsd:element name="repcomment" type="xsd:string"/>
<xsd:element name="puname" type="xsd:string"/>
<xsd:element name="puident" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="PuLogEntryArray">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:PULogEntry[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="FlashData">
<xsd:all>
<xsd:element name="wind" type="xsd:string"/>
<xsd:element name="power" type="xsd:string"/>
<xsd:element name="production" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</types>
<message name="getDataClassesRequest">
<part name="user" type="xsd:string"/>
<part name="pass" type="xsd:string"/>
<part name="pu_ident" type="xsd:string"/>
</message>
<message name="getDataClassesResponse">
<part name="return" type="tns:DataClassArray"/>
</message>
<message name="getDataFieldsRequest">
<part name="user" type="xsd:string"/>
<part name="pass" type="xsd:string"/>
<part name="pu_ident" type="xsd:string"/>
<part name="dataclass_ident" type="xsd:string"/>
</message>
<message name="getDataFieldsResponse">
<part name="return" type="tns:DataFieldArray"/>
</message>
</definitions>
从客户端项目的Web配置:
<ConsoleApplication1.Properties.Settings>
<setting name="ConsoleApplication1_RotorsoftSoapService_ROTORsoftService"
serializeAs="String">
<value>https://wpr.rotorsoft.net:443/soap.php</value>
</setting>
</ConsoleApplication1.Properties.Settings>
C#调用该服务:
RotorsoftSoapService.ROTORsoftService ws = new RotorsoftSoapService.ROTORsoftService();
var fields = ws.getDataFields("username", "password", "NX81307", "10m");
如果您想了解更多信息,请告诉我,并提前致谢!
更新 我创建了一个派生自SOAPextension的类,因此我可以在Deserilisation过程之前更改传入的XML。通过替换所有“:with”tns来解决问题: