Autor |
Beitrag |
joshua9
Beiträge: 30
|
Verfasst: So 13.08.17 18:59
Hallo
ich habe folgendes Problem:
ich möchte via SOAP auf Daten zugreifen. Dabei habe ich folgendes Problem:
beim Login muss ich die Adressnummern eingeben können-> dann gibt er diejenigen Adressen zurück
----------------------------------------------------------------------------------------------------
XML-Daten 1: 2: 3: 4: 5:
| <xsd:complexType name="tadressen"> <xsd:choice> <xsd:element minOccurs="1" maxOccurs="100" name="adressnummern" type="xsd:string" /> </xsd:choice> </xsd:complexType> |
-----------------------------------------------------------------------------------------------------
C#-Quelltext 1:
| ServiceReference1.tadressen[] ds = new ServiceReference1.tadressen[1]; |
wie kann ich die adressnummern zuweisen. Das Problem ist, dass das ganze mit PHP programmiert wurde und im WDSL FILE hat es Namespace
XML-Daten 1: 2:
| xmlns:s0="http://www.muster.com/webservices" targetNamespace="http://www.muster.com/webservices" |
ich habe auch schon versucht das WDSL File mit WDSL.exe zu bearbeiten, bekommen aber immer eine Fehlermeldung.
Vielen Dank für einen Tipp
Moderiert von Th69: XML-Tags hinzugefügt
Moderiert von Th69: C#-Tags hinzugefügt
|
|
Th69
Beiträge: 4785
Erhaltene Danke: 1055
Win10
C#, C++ (VS 2017/19/22)
|
Verfasst: So 13.08.17 20:04
Hallo,
bei dem Array solltest du dann einfach die einzelnen Elemente zuweisen können:
C#-Quelltext 1:
| ds[0] = new tadressen() { addressnummern = "..." }; |
|
|
joshua9
Beiträge: 30
|
Verfasst: So 13.08.17 20:48
Vielen Dank für die Hilfe
ist es aber nicht durch die Definition xsd im WDSL eine XML :
XML-Daten 1:
| <xsd:element minOccurs="1" maxOccurs="100" name="eGRID" type="xsd:string" /> |
Moderiert von Th69: XML-Tags hinzugefügt
|
|
Th69
Beiträge: 4785
Erhaltene Danke: 1055
Win10
C#, C++ (VS 2017/19/22)
|
Verfasst: Mo 14.08.17 08:31
Wenn das als Frage gemeint war: Nein, XML (bzw. XSD) ist nur das Definitionsformat - und daraus wird dann per WDSL C#-Code generiert.
Du kannst einfach mal mit dem Cursor (im Visual Studio) auf "tadressen" gehen und dort dann im Kontextmenü "Go to declaration (F12)" aufrufen. Das sollte dir dann die (erzeugte) C#-Definition anzeigen (sofern du vorher einmal das Projekt kompiliert hast).
|
|
joshua9
Beiträge: 30
|
Verfasst: Sa 19.08.17 13:43
Hallo
Vielen Dank, ich habe die Funktion F12 ausgeführt und das Resultat ist:
C#-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
| using System.CodeDom.Compiler; using System.ComponentModel; using System.Diagnostics; using System.Xml.Serialization;
namespace srGetTerris1 { [DebuggerStepThrough] [DesignerCategory("code")] [GeneratedCode("System.Xml", "4.7.2102.0")] [XmlType(Namespace = "http://www.muster.com/webservices")] public class tgruIdList : INotifyPropertyChanged { public tadressen();
[XmlElement("adressnummern", Order = 0)] public string[] Items { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName); } } |
----------------------------------------------------------------------------------
ich bringe es nicht fertig, dass ich diesem objekt adressnummer zufügen kann.
Vielen Dank für die Hilfe
Moderiert von Christian S.: C#-Tags hinzugefügt
Zuletzt bearbeitet von joshua9 am Sa 19.08.17 18:19, insgesamt 1-mal bearbeitet
|
|
Ralf Jansen
Beiträge: 4705
Erhaltene Danke: 991
VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
|
Verfasst: Sa 19.08.17 14:26
Das ist leider nicht der Sourcecode sondern nur die aus der Assembly disassemblierte Oberfläche deiner ServiceReference Klasse(n).
Bist du dir sicher alles kopiert zu haben? Das der Konstruktor der tgruIdList Klasse tadressen heißt ist eher unwahrscheinlich.
Was man aber aus dem Bruchstück sehen kann ist das die Property für adressnummern Items heißt. Falls die tadressen Klasse keinen Indexer implementiert (und mir wäre auch nicht bewußt das der wsdl Generator sowas kann) musst du also die Items Property zuweisen. Also in etwa
C#-Quelltext 1: 2:
| var adressen = new tadressen(); adressen.Items = new string[] { "MeineLiebeAdressNummer", "MeineLiebeAndereAdressNummer", "EtcAdressNummer" }; |
Nebenbei den Sourcecode zur ServiceReference findest du direkt im SolutionExplorer wenn du "Show all files" wie im Bild blau markiert einschaltest.
Einloggen, um Attachments anzusehen!
|
|
joshua9
Beiträge: 30
|
Verfasst: Sa 19.08.17 16:13
Vielen Dank für die Hilfe
jetzt bin ich einen Schritt weiter.
NB. bei mir erscheint das Reference.cs File nicht, obwohl ich
Verknüpfte Dateien Verschachteln (VS 2105 deutsch) eingeschaltet habe.
-------------------------------------------------------------------------------------------------------------------------
Wenn ich unter Hinzufügen -> Dienstverweis->Erweitert->Webverweis hinzufügen und dann die URL zum WDSL File hinzufüge
Kommt die Meldung 1. Dienst gefunden. Als Webverweisname gebe ich zum Beispiel getAdressen ein.
Wenn ich jetzt im ASPX Formular einen Button einfüge und danach im CS File
C#-Quelltext 1: 2: 3: 4:
| protected void Button1_Click(object sender, EventArgs e) { getAdressen } |
einfüge, kann er nicht darauf zugreifen.
Kann mir jemand einen Tipp geben.
Danke
Moderiert von Th69: C#-Tags hinzugefügt
|
|
joshua9
Beiträge: 30
|
Verfasst: Di 29.08.17 13:37
-------------------------------------------------------------------------------------------------------------------------
Wenn ich unter Hinzufügen -> Dienstverweis->Erweitert->Webverweis hinzufügen und dann die URL zum WDSL File hinzufüge
Kommt die Meldung 1. Dienst gefunden. Als Webverweisname gebe ich zum Beispiel getAdressen ein.
Wenn ich jetzt im ASPX Formular einen Button einfüge und danach im CS File
C#-Quelltext 1: 2: 3: 4:
| protected void Button1_Click(object sender, EventArgs e) { getAdressen } |
einfüge, kann er nicht darauf zugreifen.
Kann mir jemand einen Tipp geben.
Danke
Moderiert von Th69: C#-Tags hinzugefügt
|
|
Th69
Beiträge: 4785
Erhaltene Danke: 1055
Win10
C#, C++ (VS 2017/19/22)
|
Verfasst: Di 29.08.17 14:50
Der Webverweisname (engl. "web reference name") ist der Namensbereich ( namespace), d.h. verwende dafür am besten eine using-Deklaration, s.a. C#.Net How To: Consume a Web Service in C#.Net Visual Studio 2010.
|
|
joshua9
Beiträge: 30
|
Verfasst: Di 29.08.17 16:47
Danke für die Antwort, das Video habe ich auch schon gesehen.
Wenn ich es analog mache, bekommt ich folgenden Fehler :System.InvalidOperationException: "Es wurde kein standardmäßiges Endpunktelement gefunden, das auf den Vertrag
Wenn es mit PHP der WDSL aufgerufen wird funktioniert es nur bei ASP.NET nicht.
Darum habe ich versucht das WDSL nicht direkt hinzuzufügen, sondern über: Dienstverweis->Erweitert->Webverweis hinzufügen und dann die URL zum WDSL File hinzufüge.
Wenn ich es auf diesem Weg mache, dann kann ich nicht auf die WDSL-Element zugreifen, siehe unteres Mail, (er findet den ServiceReferenceName nicht)
Danke
|
|
Th69
Beiträge: 4785
Erhaltene Danke: 1055
Win10
C#, C++ (VS 2017/19/22)
|
Verfasst: Mi 30.08.17 10:36
Dann erstelle mal einen (deiner Meinung nach) fehlerfreien Code und lass dann den Compiler die Fehler anzeigen.
|
|
joshua9
Beiträge: 30
|
Verfasst: Mi 30.08.17 13:22
Vielen Dank für die Hilfe, die Fehlermeldung ist:
-------------------------------------------------------------------------------
error 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
| System.InvalidOperationException wurde nicht von Benutzercode behandelt. HResult=-2146233079 Message=Es wurde kein Endpunktelement mit dem Namen "BasicHttpBinding_Address.clsGetSoap" und dem Vertrag "ServiceReference1.clsGetSoap" im ServiceModel-Clientkonfigurationsabschnitt gefunden. Dies kann folgende Ursachen haben: Für die Anwendung wurde keine Konfigurationsdatei gefunden, oder im Clientelement wurde kein Endpunktelement gefunden, das diesem Namen entsprach. Source=System.ServiceModel StackTrace: bei System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName) bei System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration) bei System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName) bei System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address) bei System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) bei System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory() bei System.ServiceModel.ConfigurationEndpointTrait`1.CreateChannelFactory() bei System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait) bei System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef() bei System.ServiceModel.ClientBase`1..ctor(String endpointConfigurationName) bei ServiceReference1.clsGetTerrisSoapClient..ctor(String endpointConfigurationName) in c:\Temp\Temporary ASP.NET Files\vs\c9c4f35e\88e1283c\App_WebReferences._lg7lxd0.0.cs:Zeile 2262. bei _Default.Button1_Click(Object sender, EventArgs e) in c:\BegASPNET\SoabTest\Default.aspx.cs:Zeile 17. bei System.Web.UI.WebControls.Button.OnClick(EventArgs e) bei System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) bei System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) bei System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) bei System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) bei System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) InnerException: |
----------------------------------------------------------------------------------------------------------------------------------
WDSL Ausschnitt
XML-Daten 1: 2: 3: 4: 5:
| <service name="Address"> <port name="clsGetSoap" binding="s0:clsGetSoap"> <soap:address location="https://muster.com/service/v1" /> </port> </service> |
Moderiert von Th69: Code- und XML-Tags hinzugefügt
|
|
Th69
Beiträge: 4785
Erhaltene Danke: 1055
Win10
C#, C++ (VS 2017/19/22)
|
Verfasst: Mi 30.08.17 14:10
Dies ist ja dann kein Compiler-Fehler, sondern schon ein Laufzeitfehler, d.h. das Einbinden des WebServices in das Projekt hat also geklappt.
Hast du bei deinem Projekt eine "app.config" dabei?
Schau mal, ob du sie wie in Welche config-Datei wird von DLL verwendet und wo muß sie liegen? ändern bzw. erstellen kannst.
Evtl. hilft dir auch einer der folgenden Links:
WSDL in Projekt einbinden
WCF: Web Service in zweitem Web Service aufrufen
Webservicedefinition in DLL - Verwendung in EXE
Edit: bei "ASP.NET"-Projekten heißt diese Datei wohl "web.config"!
Ich habe dazu noch config web.config to use the same web service in soap and rest gefunden.
|
|
joshua9
Beiträge: 30
|
Verfasst: Mi 30.08.17 21:23
Hallo Th69
Vielen Dank für die Tipps und die Links, ich werde zuerst das ganze mit einem zugänglichen WDSL testen.
|
|
joshua9
Beiträge: 30
|
Verfasst: Mo 04.09.17 15:27
|
|
Th69
Beiträge: 4785
Erhaltene Danke: 1055
Win10
C#, C++ (VS 2017/19/22)
|
Verfasst: Mo 04.09.17 17:48
Bei https mußt du den security mode anpassen:
XML-Daten 1: 2: 3:
| <security mode="Transport"> <transport clientCredentialType="None" /> </security> |
s.a. Adding WCF Service Reference with https endpoint
PS: Demnächst füge bitte selber die passenden Code-Tags zu deinen Beiträgen hinzu.
|
|
joshua9
Beiträge: 30
|
Verfasst: Mi 06.09.17 18:55
Vielen Dank für den Hinweis
|
|
joshua9
Beiträge: 30
|
Verfasst: Sa 09.09.17 18:09
"nachdem ich gedacht habe, es wird nun funktionieren, erhalte ich die nächste Fehlermeldung:
der Fehler ist System.ServiceModel.ProtocolException: Der Inhaltstyp "text/html; charset=utf-8" der Antwortnachricht stimmt nicht mit dem Inhaltstyp der Bindung (application/soap+xml; 'charset=utf-8') überein"
im web.config File habe ich nach Suchen im Web folgende Einstellungen noch vorgenommen:
XML-Daten 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
| <system.web> <compilation debug="true" targetFramework="4.5.2"/> <httpRuntime targetFramework="4.5.2"/> <globalization requestEncoding="utf-8" responseEncoding="utf-8"/> <webServices> <protocols> <clear/> <add name="HttpSoap"/> <add name="HttpPost"/> <add name="HttpGet"/> <add name="Documentation"/> </protocols> </webServices> </system.web> |
Vielen Dank für einen Hinweis
|
|
Th69
Beiträge: 4785
Erhaltene Danke: 1055
Win10
C#, C++ (VS 2017/19/22)
|
Verfasst: So 10.09.17 08:01
Nicht das charset, sondern der Inhaltstyp scheint unterschiedlich ("text/html" <-> "application/soap+xml").
Wo du das direkt konfigurierst, weiß ich aber auch nicht - such mal danach...
|
|
joshua9
Beiträge: 30
|
Verfasst: So 10.09.17 08:44
|
|