I am consuming a web service from a third party site. I have the type and method in the wsdl file called GetItemAvailable. When i consume and execute the service it returns a SOAP array (defined in the wsdl as ItemsArray). The porblem is, i'm not sure what type i need to use to get to the information. here is my code:
GetItemAvail开发者_JAVA百科able.GetItemAvailable gia = new GetItemAvailable.GetItemAvailable();
ItemsArray ia = new ItemsArray();
ia = (gia.CallGetItemAvailable("1088507721", "9780842387491"));
string sttest = ia.id[1].ToString();
The error always says that ia.id is null
what am i doing wrong? i'm not very familiar with SOAP. Here is the wsdl:
<wsdl:definitions>
<wsdl:types>
<xsd:complexType name="Items">
<xsd:all>
<xsd:element name="item_id" type="xsd:string" />
<xsd:element name="tn_onhand" type="xsd:int" />
<xsd:element name="tn_onorder" type="xsd:string" />
<xsd:element name="tn_onorder_eta" type="xsd:string" />
<xsd:element name="nv_onhand" type="xsd:int" />
<xsd:element name="nv_onorder" type="xsd:string" />
<xsd:element name="nv_onorder_eta" type="xsd:string" />
<xsd:element name="error" type="xsd:string" />
</xsd:all>
</xsd:complexType>
<xsd:complexType name="ItemsArray">
<xsd:complexContent mixed="false">
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute wsdl:arrayType="tns:Items[]" ref="SOAP-ENC:arrayType" />
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="GetItemAvailableRequestType">
<xsd:all>
<xsd:element name="api_key" type="xsd:string" />
<xsd:element name="Items" type="xsd:string" />
</xsd:all>
</xsd:complexType>
<xsd:complexType name="GetItemAvailableResponseType">
<xsd:all>
<xsd:element name="GetItemAvailableResult" type="tns:ItemsArray" />
</xsd:all>
</xsd:complexType>
<xsd:element name="GetItemAvailable" type="tns:GetItemAvailableRequestType" />
<xsd:element name="GetItemAvailableResponse" type="tns:GetItemAvailableResponseType" />
</xsd:schema>
</wsdl:types>
<wsdl:message name="GetItemAvailableRequest">
<wsdl:part name="parameters" element="tns:GetItemAvailable" />
</wsdl:message>
<wsdl:message name="GetItemAvailableResponse">
<wsdl:part name="parameters" element="tns:GetItemAvailableResponse" />
</wsdl:message>
<wsdl:portType name="GetItemAvailablePortType">
<wsdl:operation name="GetItemAvailable">
<documentation>Returns quantity available and on order for list of products seperated by comma (example: 9780877840756,9780446691093)</documentation>
<wsdl:input message="tns:GetItemAvailableRequest" />
<wsdl:output message="tns:GetItemAvailableResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="GetItemAvailableBinding" type="tns:GetItemAvailablePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetItemAvailable">
<soap:operation soapAction="http://www.stl-distribution.com/GetItemAvailable" style="document" />
<wsdl:input>
<soap:body use="literal" namespace="http://www.stl-distribution.com" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" namespace="http://www.stl-distribution.com" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="GetItemAvailable">
<wsdl:port name="GetItemAvailablePort" binding="tns:GetItemAvailableBinding">
<soap:address location="http://www.stl-distribution.com/webservices/soap/GetItemAvailable.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Shouldn't that be
//string sttest = ia.id[1].ToString();
string sttest = ia[0].item_id;
What Henk says make sense.
Also, is this compiling for you. Based on the wsdl below:
<xsd:complexType name="Items">
<xsd:all>
<xsd:element name="item_id" type="xsd:string" />
<xsd:element name="tn_onhand" type="xsd:int" />
<xsd:element name="tn_onorder" type="xsd:string" />
<xsd:element name="tn_onorder_eta" type="xsd:string" />
<xsd:element name="nv_onhand" type="xsd:int" />
<xsd:element name="nv_onorder" type="xsd:string" />
<xsd:element name="nv_onorder_eta" type="xsd:string" />
<xsd:element name="error" type="xsd:string" />
</xsd:all>
</xsd:complexType>
I would expect ia[x].item_id - and this value should be string already.
So maybe your code should look like:
GetItemAvailable.GetItemAvailable gia = new GetItemAvailable.GetItemAvailable();
ItemsArray ia = new ItemsArray();
ia = (gia.CallGetItemAvailable("1088507721", "9780842387491"));
string sttest = ia[0].item_id;
I got the issue resolved by writting a new class to wrap around the WSDL file. Guess i should have just done this in the first place. Thanks for all the help guys!!!
public class STLItemAvailable
{
private string _itemNumber;
public string ItemNumber
{
get
{
return _itemNumber;
}
}
private int _tnOnHand;
public int TNOnHand
{
get
{
return _tnOnHand;
}
}
private int _tnOnOrder;
public int TNOnOrder
{
get
{
return _tnOnOrder;
}
}
private DateTime _tnOrderETA;
public DateTime TNOrderETA
{
get
{
return _tnOrderETA;
}
}
private int _nvOnHand;
public int NVOnHand
{
get
{
return _nvOnHand;
}
}
private int _nvOnOrder;
public int NVOnOrder
{
get
{
return _nvOnOrder;
}
}
private DateTime _nvOrderETA;
public DateTime NVOrderETA
{
get
{
return _nvOrderETA;
}
}
public STLItemAvailable()
{
//
// TODO: Add constructor logic here
//
}
public STLItemAvailable(string APIKey, string ItemNumber)
{
GetItemAvailable gia = new GetItemAvailable();
ItemsArray ia = gia.CallGetItemAvailable(APIKey, ItemNumber);
XmlElement[] XEArray = ia.Any;
XmlNode n = XEArray[0];
int testn = 0;
DateTime testd;
foreach (XmlNode xn in n.ChildNodes)
{
switch (xn.Name)
{
case "item_id":
this._itemNumber = xn.InnerText;
break;
case "tn_onhand":
int.TryParse(xn.InnerText, out testn);
this._tnOnHand = testn;
break;
case "tn_onorder":
int.TryParse(xn.InnerText, out testn);
this._tnOnOrder = testn;
break;
case "tn_onorder_eta":
DateTime.TryParse(xn.InnerText, out testd);
this._tnOrderETA = testd;
break;
case "nv_onhand":
int.TryParse(xn.InnerText, out testn);
this._nvOnHand = testn;
break;
case "nv_onorder":
int.TryParse(xn.InnerText, out testn);
this._nvOnOrder = testn;
break;
case "nv_onorder_eta":
DateTime.TryParse(xn.InnerText, out testd);
this._nvOrderETA = testd;
break;
This might or not help, but it is worth a try. Looking at the wsdl again:
<xsd:complexType name="GetItemAvailableResponseType">
<xsd:all>
<xsd:element name="GetItemAvailableResult" type="tns:ItemsArray" />
</xsd:all>
</xsd:complexType>
Seems like the Response have an object GetItemsAvailableResult that is actually f type ItemsArray.
Did you try ia.GetItemsAvailableResult[0].item_id yet?
Hopefully this will help. BTW, I added as another answer, because it would be too messy to add the code snippet within the comments.
Cheers, Wagner.
精彩评论