在C#中的SOAP客户端无法获得一个WSDL文件 [英] SOAP Client in C# without access to a WSDL-file

查看:207
本文介绍了在C#中的SOAP客户端无法获得一个WSDL文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与第三方来整合我们的一些系统与他们的,他们为我们提供了一个SOAP接口做出一定的要求和改变其连接的系统。对我来说,问题是,他们不提供一个WSDL文件,我对着干。如果我有一个WSDL文件这将是一件简单的事只是为了运行所提供的.NET命令(Wsdl.exe用),并生成一个代理类与服务进行交互。

有一个简单的方式来做到这一点没有一个WSDL文件?我有所有我们可以访问,我需要送什么参数,我应该想到回报的功能。

它是常见的有没有用WSDL文件的SOAP服务? (我问这个,因为我们将增加更多的外部系统成未来混合)

有没有人做代理类或针对WDSL无服务的任何其他形式的客户端,并且对如何做到这一点任何好的指针?

解决方案

 字符串终点=htt​​p://203.189.91.127:7777/services/spm/spm;

串New_Xml_Request_String =?&所述; XML版本= \1.0 \编码= \UTF-8 \&GT;&所述; soapenv:信封的xmlns:soapenv = \http://schemas.xmlsoap.org/soap/信封/ \的xmlns:XSD = \HTTP://www.w3.org/2001/XMLSchema \ xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soapenv:Body><OTA_AirLowFareSearchRQ EchoToken = \0 \SequenceNmbr = \0 \TransactionIdentifier = \0 \的xmlns = \HTTP://www.opentravel.org/OTA/2003/05 \&GT;&LT; POS的xmlns = \ http://www.opentravel.org/OTA/2003/05\"><Source AgentSine = \\PseudoCity code = \NPCK \TerminalID = \1 \&GT;&LT ; RequestorID ID = \\/&GT;&LT; /来源&GT;&LT; YatraRequests&GT;&LT; YatraRequest DoNotHitCache = \真正的\DoNotCache = \假\MidOfficeAgentID = \\AffiliateID = \\ YatraRequestType$c$c=\"SMPA\"/></YatraRequests></POS><TravelerInfoSummary><AirTravelerAvail><PassengerTypeQuantity code = \ADT \数量= \1 \/&GT;&LT; PassengerTypeQuantity code = \CHD \数量= \1 \/&GT;&LT; PassengerTypeQuantity code = \INF \数量= \1 \/&GT;&LT; / AirTravelerAvail&GT;&LT; / TravelerInfoSummary&GT;&LT; SpecificFlightInfo&GT;&LT;航空公司$c$c=\"\"/></SpecificFlightInfo><OriginDestinationInformation><DepartureDateTime>" + DateTime.Now.ToString(O),删除(19,14)+&LT; / DepartureDateTime&GT;&LT; OriginLocation codeContext = \国际航空运输协会\位置code = \DEL \&GT ;+源码+&LT; / OriginLocation&GT;&LT; D​​estinationLocation codeContext = \国际航空运输协会\位置code = \BOM \&gt;中+ Destincation + "</DestinationLocation></OriginDestinationInformation><Travel$p$pferences><Cabin$p$pf Cabin=\"Economy\"/></Travel$p$pferences></OTA_AirLowFareSearchRQ></soapenv:Body></soapenv:Envelope>";


 保护字符串HttpSOA prequest_Test(字符串XMLFILE,串代理)
    {
        尝试
        {
            System.Xml.XmlDocument DOC =新System.Xml.XmlDocument();
            doc.InnerXml = xmlfile.ToString();
            HttpWebRequest的REQ =(HttpWebRequest的)WebRequest.Create(终点);
            req.Timeout =亿;
            如果(代理!= NULL)
                req.Proxy =新WebProxy(代理,真正的);
            req.Headers.Add(SOAPAction的,);
            req.Co​​ntentType =应用程序/肥皂+ XML;字符集= \UTF-8 \;
            req.Accept =应用/的X WWW的形式urlen codeD; //应用程序/肥皂+ XML;
            req.Method =POST;
            流STM = req.GetRequestStream();
            doc.Save(STM);
            stm.Close();
            WebResponse类RESP = req.GetResponse();
            STM = resp.GetResponseStream();
            StreamReader的R =新的StreamReader(STM);
            字符串MYD = r.ReadToEnd();
            返回MYD;
        }

   赶上(例外SE)
        {
            抛出新的异常(错误发生在AuditAdapter.getXMLDocumentFromXMLTemplate(),SE);
        }
    }
 

I'm working with a third party to integrate some of our systems with theirs and they provide us with a SOAP interface to make certain requests and changes in their connected systems. The problem for me is that they do not supply a WSDL-file for me to work against. If I had a WSDL-file it would be a simple matter just to run the supplied .NET command (wsdl.exe) and generate a proxy class to interact with the service.

Is there an "easy" way to do this without a WSDL-file? I have all the functions that we can access and what parameters I need to send and what I should expect in return.

Is it common to have a SOAP-service without WSDL-files? (I'm asking this since we're going to add more external systems into the mix in the future)

Has anyone done a proxy-class or any other form of client against a WDSL-less service and have any good pointers on how to do it?

解决方案

string EndPoints = "http://203.189.91.127:7777/services/spm/spm";

string New_Xml_Request_String = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soapenv:Body><OTA_AirLowFareSearchRQ EchoToken=\"0\" SequenceNmbr=\"0\" TransactionIdentifier=\"0\" xmlns=\"http://www.opentravel.org/OTA/2003/05\"><POS xmlns=\"http://www.opentravel.org/OTA/2003/05\"><Source AgentSine=\"\" PseudoCityCode=\"NPCK\"  TerminalID=\"1\"><RequestorID ID=\"\"/></Source><YatraRequests><YatraRequest DoNotHitCache=\"true\" DoNotCache=\"false\" MidOfficeAgentID=\"\" AffiliateID=\"\" YatraRequestTypeCode=\"SMPA\"/></YatraRequests></POS><TravelerInfoSummary><AirTravelerAvail><PassengerTypeQuantity Code=\"ADT\" Quantity=\"1\"/><PassengerTypeQuantity Code=\"CHD\" Quantity=\"1\"/><PassengerTypeQuantity Code=\"INF\" Quantity=\"1\"/></AirTravelerAvail></TravelerInfoSummary> <SpecificFlightInfo><Airline Code=\"\"/></SpecificFlightInfo><OriginDestinationInformation><DepartureDateTime>" + DateTime.Now.ToString("o").Remove(19, 14) + "</DepartureDateTime><OriginLocation CodeContext=\"IATA\" LocationCode=\"DEL\">" + Source + "</OriginLocation><DestinationLocation CodeContext=\"IATA\" LocationCode=\"BOM\">" + Destincation + "</DestinationLocation></OriginDestinationInformation><TravelPreferences><CabinPref Cabin=\"Economy\"/></TravelPreferences></OTA_AirLowFareSearchRQ></soapenv:Body></soapenv:Envelope>";


 protected string HttpSOAPRequest_Test(string xmlfile, string proxy)
    {
        try
        {
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.InnerXml = xmlfile.ToString();
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(EndPoints);
            req.Timeout = 100000000;
            if (proxy != null)
                req.Proxy = new WebProxy(proxy, true);
            req.Headers.Add("SOAPAction", "");
            req.ContentType = "application/soap+xml;charset=\"utf-8\"";
            req.Accept = "application/x-www-form-urlencoded"; //"application/soap+xml";
            req.Method = "POST";
            Stream stm = req.GetRequestStream();
            doc.Save(stm);
            stm.Close();
            WebResponse resp = req.GetResponse();
            stm = resp.GetResponseStream();
            StreamReader r = new StreamReader(stm);
            string myd = r.ReadToEnd();
            return myd;
        }

   catch (Exception se)
        {
            throw new Exception("Error Occurred in AuditAdapter.getXMLDocumentFromXMLTemplate()", se);
        }
    }

这篇关于在C#中的SOAP客户端无法获得一个WSDL文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆