13

我正在与第三方合作,将我们的一些系统与他们的系统集成在一起,他们为我们提供了一个 SOAP 接口,以便在他们连接的系统中提出某些请求和更改。对我来说,问题是他们没有提供 WSDL 文件供我使用。如果我有一个 WSDL 文件,那么只需运行提供的 .NET 命令 (wsdl.exe) 并生成一个代理类来与服务交互就可以了。

没有 WSDL 文件有没有“简单”的方法来做到这一点?我拥有我们可以访问的所有功能以及我需要发送的参数以及我应该期望的回报。

没有 WSDL 文件的 SOAP 服务很常见吗?(我问这个是因为我们将来会添加更多的外部系统)

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

4

4 回答 4

7
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);
        }
    }
于 2010-09-14T10:46:41.550 回答
4

如果您编写的类派生自System.Web.Services.Protocols.SoapHttpClientProtocol(并具有正确的属性,例如,WebServiceBinding应用SoapDocumentMethod到它及其方法),您可以相当容易地调用 SOAP 方法,而无需 WSDL 文件。

最简单的方法可能是编写自己的 ASP.NET Web 服务来复制第三方的 SOAP API,从中生成代理类,然后手动编辑文件以确保 URL、命名空间、方法名称、参数types 等对于您要调用的第三方 API 是正确的。

于 2008-11-10T15:01:59.107 回答
1

我还没有构建一个没有访问 WSDL 文件的 SOAP 接口,但是格式是相当有据可查的。您最好的选择可能是创建一个您自己的简化 WSDL 文件,以反映您对所订阅服务的了解......

如果您决定走这条路,现有的 stackoverflow 问题指向一些用于验证您的 WSDL 的工具。

于 2008-11-10T15:01:41.337 回答
1

the code here is in VB.NET but I think you'll get the idea. The following is a client that invokes the 'processConfirmation' method and it expects a response (MyBase.SendRequestResponse).

Imports Microsoft.Web.Services3
Imports Microsoft.Web.Services3.Addressing
Imports Microsoft.Web.Services3.Messaging

Namespace Logic
    Public Class HTTPClient
        Inherits Soapclient

        Sub New(ByVal destination As EndpointReference)
            MyBase.Destination = destination
        End Sub

        <SoapMethod("processConfirmation")> _
        Public Function processConfirmation(ByVal envelope As SoapEnvelope) As SoapEnvelope
            Return MyBase.SendRequestResponse("processConfirmation", envelope)
        End Function
    End Class
End Namespace

And you use it by doing the following:

Dim hc As New HTTPClient(New Microsoft.Web.Services3.Addressing.EndpointReference(New System.Uri("http://whatever.srv")))

Dim envelope As New Microsoft.Web.Services3.SoapEnvelope
Dim doc As New Xml.XmlDocument
doc.LoadXml("<hey>there</hey>")
envelope.SetBodyObject(doc)

Dim return_envelope As Microsoft.Web.Services3.SoapEnvelope = hc.processConfirmation(envelope)

I think this should work .... success!

于 2009-01-05T14:57:04.357 回答