我正在开发WP7 Silverlight应用程序并使用基于SOAP(类型文档/文字),WSDL和PHP的webservice。抱歉这样的捷径,但我对webservices的了解并不是很好。
我有方法cardList的问题,它返回Card对象的数组,但其他方法可以正常工作。当我调用我的方法时,cardList请求转到服务器并且发回的响应也没问题但是在代码方法中返回数组Card [0]什么是不正确的,因为服务器发送了带有单元素数组的XML。我认为问题在于反序列化。
你知道如何修复它吗?
WSDL部分:
<xsd:complexType name="Card">
<xsd:all>
<xsd:element name="id" type="xsd:string" />
<xsd:element name="pan" type="xsd:string" />
<xsd:element name="default" type="xsd:integer" />
<xsd:element name="auth_type" type="xsd:string" />
<xsd:element minOccurs="0" name="exp_date" type="xsd:string" />
<xsd:element minOccurs="0" name="authorized" type="xsd:string" />
<xsd:element minOccurs="0" name="used" type="xsd:integer" />
<xsd:element minOccurs="0" name="freezed" type="xsd:boolean" />
<xsd:element minOccurs="0" name="nickname" type="xsd:string" />
<xsd:element minOccurs="0" name="card_type" type="xsd:string" />
<xsd:element minOccurs="0" name="SM_name" type="xsd:string" />
</xsd:all>
</xsd:complexType>
<xsd:complexType name="cardList">
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="1000" name="cardListElement" type="tns:Card" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="cardsListResponseType">
<xsd:sequence>
<xsd:element name="status" type="xsd:integer" />
<xsd:element minOccurs="0" name="cards" type="tns:cardList" />
</xsd:sequence>
</xsd:complexType>
代理类:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="cardsListResponse", WrapperNamespace="test.abc.pl", IsWrapped=true)]
public partial class cardsListResponse {
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="test.abc.pl", Order=0)]
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType="integer")]
public string status;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="test.abc.pl", Order=1)]
[System.Xml.Serialization.XmlArray("cards")]
[System.Xml.Serialization.XmlArrayItemAttribute("cardListElement")]
public mPotwor.uPaidAPI.Card[] cards;
public cardsListResponse() {
}
public cardsListResponse(string status, mPotwor.uPaidAPI.Card[] cards) {
this.status = status;
this.cards = cards;
}
}
来自服务器的响应:
HTTP/1.1 200 OK
Date: Sat, 01 Dec 2012 18:06:36 GMT
Server: Apache
X-Powered-By: PHP/5.4.8
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Set-Cookie: PHPSESSID=e410948ae3b472952db1fabf4d211ff3; path=/; HttpOnly
Set-Cookie: PHPSESSID=9d943ed283935eb5618b275d9c6c5727; path=/; HttpOnly
Content-Length: 725
Keep-Alive: timeout=12, max=99999
Connection: Keep-Alive
Content-Type: text/xml; charset=UTF-8
<?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"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<cardsListResponse xmlns="test.abc.pl">
<status>1</status>
<cards>
<cardListElement>
<id>1017</id>
<pan>XXXX-XXXX-XXXX-6321</pan>
<default>1</default>
<auth_type>cvc2</auth_type>
<exp_date>07/13</exp_date>
<authorized>0</authorized>
<used>0</used>
<freezed>false</freezed>
<nickname>XXXX-XXXX-XXXX-6321</nickname>
<card_type>visa</card_type>
<SM_name>abc</SM_name>
</cardListElement>
</cards>
</cardsListResponse>
</SOAP-ENV:Body>