简体   繁体   English

将SOAP转换为C#类时遇到麻烦

[英]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 : 我正在使用Web服务(SOAP),但无法引用Web应用程序,因此正在尝试对响应SOAP消息进行序列化,但出现此错误:

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

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 这是SOAP响应: XML

You won't be able to directly deserialize a SOAP envelope to a custom type. 您将无法直接将SOAP信封反序列化为自定义类型。 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. 您将解析xml并提取数据,然后手动创建您的类型的实例,或者构建一个极其复杂的自定义xml序列化程序。

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. 您将获得一个代理客户端,可以像调用其他任何对象一样对其进行调用,但是它将为您进行Web服务调用。

In your project right-click References and select Add Service Reference... . 在项目中,右键单击“ References然后选择“ Add Service Reference... Int the Address box, put the service's wsdl location, which is this: 在“ Address框中,放入服务的wsdl位置,即:

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). 您可能希望将名称空间从ServiceReference1更改为EpowerSvc或其他任何名称- 只是不要使用点分名称 (即: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 : 我不确定您的示例代码正在调用哪种方法,但是我猜它是SearchFlight

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

 //use result
 result.Items...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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