简体   繁体   中英

trouble converting SOAP to C# class

i'm working on a web service (SOAP) and i can't reference the web application i'm trying to Serialize the response SOAP massage but i get this error :

http://schemas.xmlsoap.org/soap/envelope/'> was not expected

i'm using this :

  XmlSerializer serializer = new XmlSerializer(typeof(SearchFlightResponse));                       
        SearchFlightResponse result = (SearchFlightResponse)serializer.Deserialize(XmlReader.Create("file:///D:/SR_response.xml"));

and this is the SOAP response : XML

You won't be able to directly deserialize a SOAP envelope to a custom type. You would have parse the xml and extract the data then manually create an instance of your type, or build an extremely complex custom xml serializer.

You can save yourself days of work if you add this service as a Service Reference. You will get a proxy client that you can make calls on like it was just any other object, but it will make the web service calls for you.

In your project right-click References and select Add Service Reference... . Int the Address box, put the service's wsdl location, which is this:

https://ws.epower.amadeus.com/demo.WS/EpowerService.asmx?wsdl

You will probably want to change the namespace from ServiceReference1 to EpowerSvc or whatever - just do not use a dotted name (ie: Epower.Service).

Now you can create a client and call methods. I'm not sure which method you are calling by your sample code, but I'm guessing it is SearchFlight :

 EpowerSvc.EpowerServiceSoapClient client = new EpowerSvc.EpowerServiceSoapClient();
 SearchFlightCalendarResponseOTA_AirLowFareSearchRS result = client.SearchFlight( someparam, someparam2, someparam3);

 //use result
 result.Items...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM