![]() |
Webservice Daten in ein Datagrid bekommen
Ich übe gerade etwas mit Webservices und habe mir diesen hier vorgenommen:
![]() Er beinhaltet eine Liste von Restaurants. Gibt es da irgendwie eine Möglichkeit alle Restaurants mit ihren Eigenschaften einfach in ein DataGrid zu stopfen? Ungefähr so:
Code:
Der Code funktioniert allerdings nicht, das DatenGrid bleibt leer. ;)
RestaurantServiceService rs = new RestaurantServiceService();
dataGridView1.DataSource = rs.getRestaurants(); |
Re: Webservice Daten in ein Datagrid bekommen
Nachtrag:
Code:
Wenn ich es so mache, habe ich schon mal 68 Zeilen im Grid und so viele Restaurants sind es auch. Nur sit das Grid leider leer. :gruebel:
private void btnGetReastaurants_Click(object sender, EventArgs e)
{ dataGridView1.ColumnCount = 2; dataGridView1.DataSource = restaurantServiceService1.getRestaurants(); } Der Versuch das ganze in eine IList<Restaurant> ls = restaurantServiceService1.getRestaurants(); ist auch fehlgeschlagen mit der Fehlermeldung Zitat:
|
Re: Webservice Daten in ein Datagrid bekommen
Welchen Datentyp liefert die Methode getRestaurants() denn zurück?
|
Re: Webservice Daten in ein Datagrid bekommen
Ja, das wüßte ich auch mal gerne. Wenn ich das richtig sehe:
XML-Code:
Ist das vom Typ soapenc:Array, was auch immer das ist.
<wsdl:message name="getRestaurantsRequest">
</wsdl:message> − <wsdl:message name="getRestaurantsResponse"> <wsdl:part name="getRestaurantsReturn" type="soapenc:Array"/> </wsdl:message> ... <wsdl:operation name="getRestaurants"> <wsdl:input name="getRestaurantsRequest" message="impl:getRestaurantsRequest"/> <wsdl:output name="getRestaurantsResponse" message="impl:getRestaurantsResponse"/> </wsdl:operation> |
Re: Webservice Daten in ein Datagrid bekommen
Hey Luckie,
hab mir interessehalber den Webservice mal genauer angesehn. So wie's aussieht beinhaltet jedes object in dem object-array dass du mit "getRestaurants()" bekommst nochmal ein Array von XmlNodes. Hab das testweise mal mit ner ListBox ausprobiert, ich poste dir hier mal meinen Code. Sollte ja für dich keine Schwierigkeit sein das in ein DataGridView zu übertragen :wink:
Code:
Hoffe du kannst damit was anfangenprivate void btnGetRestaurants_Click(object sender, EventArgs e) { RestaurantService.RestaurantServiceService rs = new WindowsApplication1.RestaurantService.RestaurantServiceService(); object[] restaurants = rs.getRestaurants(); for(int i = 0; i < restaurants.Length; i++) { XmlNode[] nodes = (XmlNode[])restaurants[i]; for(int j = 0; j < nodes.Length; j++) listBox1.Items.Add(nodes[j].InnerText); } } |
Re: Webservice Daten in ein Datagrid bekommen
Ah. dann geht es wohl doch nicht so einfach, wie ich es dachte. Ich werde mir das morgen mal genauer angucken, jetzt ist erstmal Feierabend. ;)
|
Re: Webservice Daten in ein Datagrid bekommen
Hm, zu Huase mit Delphi 2006 bekomme ich immer diese Fehlermeldung:
Zitat:
|
Re: Webservice Daten in ein Datagrid bekommen
Die gleiche Fehlermeldung bekam ich beim Visual Studio 2003 auch, mit der 2005er Version gings.
Ich vermute mal dass der Webservice nur zum 2.0er .NET Framework kompatibel ist, zumindest kann ich mir das nicht anders erklären. Wenn du dich nen bissl in C# einarbeiten willst, würd ich dir sowieso eher zur Express-Version vom VS 2005 raten, oder alternativ #develop 2.0 |
Re: Webservice Daten in ein Datagrid bekommen
Nun ja, an der Arbeit habe ich das VS 2005, aber zu Hause eben nicht. aber mal sehen, was ich da morgen an der Arbeit draus mache. Es wäre aber schön, wenn man das irgendwie elegant in den DataGridView bekommen könnte. Sonst ist das Ding doch immer so schlau. :gruebel:
|
Re: Webservice Daten in ein Datagrid bekommen
Das WSDL ist falsch. Es validiert nicht gegen das mitgelieferte Schema.
Außerdem sind ein paar Typen krum deklariert. Deshalb vekommst du einen Array of Object statt Restaurant. ;) Entweder du nimmst ein funktionierendes Sample oder du musst das WSDL selbst korrigieren. Die Schemafehler, die dein Studio ausgibt wenn du das WSDL darin öffnest sollten dir dabei helfen können. ;) |
Re: Webservice Daten in ein Datagrid bekommen
Die WDSL hat mir das VS erstellt. Und im Moment sehe ich mich nicht in der Lage sie zu korrigieren. :( Desweiteren ist es nur eine Übung für mich, wie man mit Webservices Arbeitet. Letztendlich muss ich mit einem Webservice aus der Firma kommunizieren, der aber noch nicht existiert. Ein Kollege arbeitet mit dem selben Webservice unter Flex und damit scheint es zu gehen. Könnte mir jemand die WDSL korrigieren? Wäre das viel Arbeit? Und wie bekomme ich dann die korrigierte WDSL ins VS? Ich habe sie bisher über "Webverweis hinzufügen" importiert. Das VS hat mir dann auch gleich eine Komponente erstellt, die man benutzen kann.
|
Re: Webservice Daten in ein Datagrid bekommen
Sodele, an der Arbeit.
XML-Code:
Zeile 9 hat er mir markiert und zwar das xsd:import mit dem Hinweis "Importiertes Schema für den Namespace wurde nicht aufgelöst". Ebendso Zeile 11, 28, 53 und 56. Das sind wohl die Arrays. Was kann ich da jetzt tun?
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:tns1="http://www.macromedia.com/samples" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:impl="http://flexapps.macromedia.com/ws/services/RestaurantWS" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:intf="http://flexapps.macromedia.com/ws/services/RestaurantWS" targetNamespace="http://flexapps.macromedia.com/ws/services/RestaurantWS" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> <wsdl:types> <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.macromedia.com/samples"> <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" /> <xsd:complexType name="RestaurantCategory"> <xsd:sequence> <xsd:element name="categoryId" type="xsd:int" /> <xsd:element name="name" nillable="true" type="xsd:string" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="RestaurantSummary"> <xsd:sequence> <xsd:element name="city" nillable="true" type="xsd:string" /> <xsd:element name="name" nillable="true" type="xsd:string" /> <xsd:element name="restaurantId" type="xsd:int" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="Restaurant"> <xsd:sequence> <xsd:element name="address" nillable="true" type="xsd:string" /> <xsd:element name="categories" nillable="true" type="soapenc:Array" /> <xsd:element name="city" nillable="true" type="xsd:string" /> <xsd:element name="description" nillable="true" type="xsd:string" /> <xsd:element name="image" nillable="true" type="xsd:string" /> <xsd:element name="link" nillable="true" type="xsd:string" /> <xsd:element name="name" nillable="true" type="xsd:string" /> <xsd:element name="phone" nillable="true" type="xsd:string" /> <xsd:element name="rating" type="xsd:int" /> <xsd:element name="restaurantId" type="xsd:int" /> <xsd:element name="zip" nillable="true" type="xsd:string" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="Review"> <xsd:sequence> <xsd:element name="rating" type="xsd:int" /> <xsd:element name="restaurantId" type="xsd:int" /> <xsd:element name="reviewDate" nillable="true" type="xsd:dateTime" /> <xsd:element name="reviewText" nillable="true" type="xsd:string" /> <xsd:element name="reviewer" nillable="true" type="xsd:string" /> <xsd:element name="title" nillable="true" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:schema> <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://flexapps.macromedia.com/ws/services/RestaurantWS"> <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" /> <xsd:complexType name="ArrayOf_xsd_int"> <xsd:complexContent mixed="false"> <xsd:restriction base="soapenc:Array"> <xsd:attribute wsdl:arrayType="xsd:int[]" ref="soapenc:arrayType" /> </xsd:restriction> </xsd:complexContent> </xsd:complexType> </xsd:schema> </wsdl:types> <wsdl:message name="getCategoriesRequest"> <wsdl:part name="restaurantId" type="xsd:int" /> </wsdl:message> <wsdl:message name="getRestaurantRequest"> <wsdl:part name="restaurantId" type="xsd:int" /> </wsdl:message> <wsdl:message name="getReviewsRequest"> <wsdl:part name="restaurantId" type="xsd:int" /> </wsdl:message> <wsdl:message name="getRestaurantResponse"> <wsdl:part name="getRestaurantReturn" type="tns1:Restaurant" /> </wsdl:message> <wsdl:message name="getCategoriesResponse"> <wsdl:part name="getCategoriesReturn" type="soapenc:Array" /> </wsdl:message> <wsdl:message name="getRestaurantsRequest" /> <wsdl:message name="getRestaurantsResponse"> <wsdl:part name="getRestaurantsReturn" type="soapenc:Array" /> </wsdl:message> <wsdl:message name="addReviewResponse" /> <wsdl:message name="addReviewRequest"> <wsdl:part name="review" type="tns1:Review" /> </wsdl:message> <wsdl:message name="getRestaurantsByCategoriesResponse"> <wsdl:part name="getRestaurantsByCategoriesReturn" type="soapenc:Array" /> </wsdl:message> <wsdl:message name="getReviewsResponse"> <wsdl:part name="getReviewsReturn" type="soapenc:Array" /> </wsdl:message> <wsdl:message name="getRatingResponse"> <wsdl:part name="getRatingReturn" type="xsd:int" /> </wsdl:message> <wsdl:message name="getRatingRequest"> <wsdl:part name="restaurantId" type="xsd:int" /> </wsdl:message> <wsdl:message name="getRestaurantsByCategoriesRequest"> <wsdl:part name="categories" type="intf:ArrayOf_xsd_int" /> </wsdl:message> <wsdl:portType name="RestaurantService"> <wsdl:operation name="getCategories" parameterOrder="restaurantId"> <wsdl:input name="getCategoriesRequest" message="intf:getCategoriesRequest" /> <wsdl:output name="getCategoriesResponse" message="intf:getCategoriesResponse" /> </wsdl:operation> <wsdl:operation name="getRating" parameterOrder="restaurantId"> <wsdl:input name="getRatingRequest" message="intf:getRatingRequest" /> <wsdl:output name="getRatingResponse" message="intf:getRatingResponse" /> </wsdl:operation> <wsdl:operation name="getRestaurants"> <wsdl:input name="getRestaurantsRequest" message="intf:getRestaurantsRequest" /> <wsdl:output name="getRestaurantsResponse" message="intf:getRestaurantsResponse" /> </wsdl:operation> <wsdl:operation name="getRestaurantsByCategories" parameterOrder="categories"> <wsdl:input name="getRestaurantsByCategoriesRequest" message="intf:getRestaurantsByCategoriesRequest" /> <wsdl:output name="getRestaurantsByCategoriesResponse" message="intf:getRestaurantsByCategoriesResponse" /> </wsdl:operation> <wsdl:operation name="getRestaurant" parameterOrder="restaurantId"> <wsdl:input name="getRestaurantRequest" message="intf:getRestaurantRequest" /> <wsdl:output name="getRestaurantResponse" message="intf:getRestaurantResponse" /> </wsdl:operation> <wsdl:operation name="getReviews" parameterOrder="restaurantId"> <wsdl:input name="getReviewsRequest" message="intf:getReviewsRequest" /> <wsdl:output name="getReviewsResponse" message="intf:getReviewsResponse" /> </wsdl:operation> <wsdl:operation name="addReview" parameterOrder="review"> <wsdl:input name="addReviewRequest" message="intf:addReviewRequest" /> <wsdl:output name="addReviewResponse" message="intf:addReviewResponse" /> </wsdl:operation> </wsdl:portType> <wsdl:binding name="RestaurantWSSoapBinding" type="intf:RestaurantService"> <wsdlsoap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" /> <wsdl:operation name="getCategories"> <wsdlsoap:operation soapAction="" /> <wsdl:input name="getCategoriesRequest"> <wsdlsoap:body use="encoded" namespace="http://restaurant.samples" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </wsdl:input> <wsdl:output name="getCategoriesResponse"> <wsdlsoap:body use="encoded" namespace="http://flexapps.macromedia.com/ws/services/RestaurantWS" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="getRating"> <wsdlsoap:operation soapAction="" /> <wsdl:input name="getRatingRequest"> <wsdlsoap:body use="encoded" namespace="http://restaurant.samples" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </wsdl:input> <wsdl:output name="getRatingResponse"> <wsdlsoap:body use="encoded" namespace="http://flexapps.macromedia.com/ws/services/RestaurantWS" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="getRestaurants"> <wsdlsoap:operation soapAction="" /> <wsdl:input name="getRestaurantsRequest"> <wsdlsoap:body use="encoded" namespace="http://restaurant.samples" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </wsdl:input> <wsdl:output name="getRestaurantsResponse"> <wsdlsoap:body use="encoded" namespace="http://flexapps.macromedia.com/ws/services/RestaurantWS" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="getRestaurantsByCategories"> <wsdlsoap:operation soapAction="" /> <wsdl:input name="getRestaurantsByCategoriesRequest"> <wsdlsoap:body use="encoded" namespace="http://restaurant.samples" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </wsdl:input> <wsdl:output name="getRestaurantsByCategoriesResponse"> <wsdlsoap:body use="encoded" namespace="http://flexapps.macromedia.com/ws/services/RestaurantWS" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="getRestaurant"> <wsdlsoap:operation soapAction="" /> <wsdl:input name="getRestaurantRequest"> <wsdlsoap:body use="encoded" namespace="http://restaurant.samples" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </wsdl:input> <wsdl:output name="getRestaurantResponse"> <wsdlsoap:body use="encoded" namespace="http://flexapps.macromedia.com/ws/services/RestaurantWS" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="getReviews"> <wsdlsoap:operation soapAction="" /> <wsdl:input name="getReviewsRequest"> <wsdlsoap:body use="encoded" namespace="http://restaurant.samples" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </wsdl:input> <wsdl:output name="getReviewsResponse"> <wsdlsoap:body use="encoded" namespace="http://flexapps.macromedia.com/ws/services/RestaurantWS" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="addReview"> <wsdlsoap:operation soapAction="" /> <wsdl:input name="addReviewRequest"> <wsdlsoap:body use="encoded" namespace="http://restaurant.samples" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </wsdl:input> <wsdl:output name="addReviewResponse"> <wsdlsoap:body use="encoded" namespace="http://flexapps.macromedia.com/ws/services/RestaurantWS" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="RestaurantServiceService"> <wsdl:port name="RestaurantWS" binding="intf:RestaurantWSSoapBinding"> <wsdlsoap:address location="http://flexapps.macromedia.com/ws/services/RestaurantWS" /> </wsdl:port> </wsdl:service> </wsdl:definitions> |
Re: Webservice Daten in ein Datagrid bekommen
Also ich weiß nicht, was ich wie in der WDSL Datei ändern/anpassen muss. Leider habe ich zu der WDSL Datei auch keine Dokumentation gefunden oder bei Macromedia irgendwas hilfreiches.
|
Re: Webservice Daten in ein Datagrid bekommen
Wieso nimmst du nicht meinen Code als Grundlage?
Wie gesagt, jedes object im Array enthält wiederum nochmal XmlNodes, eleganter wird sich das wohl nicht lösen lassen Beschädigt ist die WSDL-Datei nämlich nicht, nur die Darstellung im DataGridView ist wohl ein wenig aufwendiger als gewohnt. Und etwas an der Datei zu ändern würde gegen jeden Sinn eines Webservices sprechen, da die Datei ja auf nem fremden Server gehostet wird. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:48 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz