Jump to content
  • 0
jinsheng peng

mangos zero How can I connect to SOAP through C # or java

Question

How can I connect to SOAP through C # or java? According to demo, I can use PHP to connect normally, but I can't generate a wsdl file, so I can't use C # or Java to connect successfully. I have read a lot about gsoap, but still can't connect, so I can only come here for help. Thank you for your reply.
My mailbox    [email protected]

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0
23 hours ago, jladd45205 said:

Yes you can connect to the SOAP Endpoints via C#.  Although u cant generate the WSDL, u can manually setup the Envelope XML yourself and send it as a normal web request.  Below is some sample code I used to send money via mail to a specific account.  You just need to look at the source on how the SOAP endpoint is reading the incoming stuff and then reverse engineer it.  

public async Task SendMoney(string charecter, long quanity)
        {
            var realm = await _forumnDB.Realms.FindAsync(_realmID);

            if (!string.IsNullOrWhiteSpace(realm.SoapIP) && realm.SoapPort > 0 && !string.IsNullOrWhiteSpace(realm.SoapUserName) && !string.IsNullOrWhiteSpace(realm.SoapPassword))
            {
                XmlDocument soapEnvelopeXml = GetXMLDoc(string.Format("send money {0} \"Approved GM Request Money\" \"Attached is the money you requested\" {1}\n", charecter, quanity));
                HttpWebRequest webRequest = CreateWebRequest(string.Format("http://{0}:{1}", realm.SoapIP, realm.SoapPort), realm.SoapUserName, realm.SoapPassword);
                InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

                // begin async call to web request.
                IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);

                // suspend this thread until call is complete. You might want to
                // do something usefull here like update your UI.
                asyncResult.AsyncWaitHandle.WaitOne();

                // get the response from the completed web request.
                string soapResult;
                using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
                {
                    using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                    {
                        soapResult = rd.ReadToEnd();
                    }

                }
            }
            else
            {

            }
        }

        XmlDocument GetXMLDoc(string command)
        {
            XmlDocument soapEnvelopeDocument = new XmlDocument();
            soapEnvelopeDocument.LoadXml(string.Format(@"<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:SOAP-ENC=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:xsi=""http://www.w3.org/1999/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/1999/XMLSchema"" xmlns:ns1=""urn:MaNGOS""><SOAP-ENV:Body><ns1:executeCommand><command>{0}</command></ns1:executeCommand></SOAP-ENV:Body></SOAP-ENV:Envelope> ", command));
            return soapEnvelopeDocument;
        }

        HttpWebRequest CreateWebRequest(string url, string username, string password)
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Credentials = new NetworkCredential(username, password);
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";
            return webRequest;
        }

        static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
        {
            using (Stream stream = webRequest.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }
        }

 

Thank you very much for your reply. I successfully connected to the server.

Share this post


Link to post
Share on other sites
  • 0

Yes you can connect to the SOAP Endpoints via C#.  Although u cant generate the WSDL, u can manually setup the Envelope XML yourself and send it as a normal web request.  Below is some sample code I used to send money via mail to a specific account.  You just need to look at the source on how the SOAP endpoint is reading the incoming stuff and then reverse engineer it.  

public async Task SendMoney(string charecter, long quanity)
        {
            var realm = await _forumnDB.Realms.FindAsync(_realmID);

            if (!string.IsNullOrWhiteSpace(realm.SoapIP) && realm.SoapPort > 0 && !string.IsNullOrWhiteSpace(realm.SoapUserName) && !string.IsNullOrWhiteSpace(realm.SoapPassword))
            {
                XmlDocument soapEnvelopeXml = GetXMLDoc(string.Format("send money {0} \"Approved GM Request Money\" \"Attached is the money you requested\" {1}\n", charecter, quanity));
                HttpWebRequest webRequest = CreateWebRequest(string.Format("http://{0}:{1}", realm.SoapIP, realm.SoapPort), realm.SoapUserName, realm.SoapPassword);
                InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

                // begin async call to web request.
                IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);

                // suspend this thread until call is complete. You might want to
                // do something usefull here like update your UI.
                asyncResult.AsyncWaitHandle.WaitOne();

                // get the response from the completed web request.
                string soapResult;
                using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
                {
                    using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                    {
                        soapResult = rd.ReadToEnd();
                    }

                }
            }
            else
            {

            }
        }

        XmlDocument GetXMLDoc(string command)
        {
            XmlDocument soapEnvelopeDocument = new XmlDocument();
            soapEnvelopeDocument.LoadXml(string.Format(@"<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:SOAP-ENC=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:xsi=""http://www.w3.org/1999/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/1999/XMLSchema"" xmlns:ns1=""urn:MaNGOS""><SOAP-ENV:Body><ns1:executeCommand><command>{0}</command></ns1:executeCommand></SOAP-ENV:Body></SOAP-ENV:Envelope> ", command));
            return soapEnvelopeDocument;
        }

        HttpWebRequest CreateWebRequest(string url, string username, string password)
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Credentials = new NetworkCredential(username, password);
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";
            return webRequest;
        }

        static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
        {
            using (Stream stream = webRequest.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }
        }

 

Edited by jladd45205
  • Like 1

Share this post


Link to post
Share on other sites

Contact Us

To contact us click here
You can also email us at [email protected]

Privacy Policy | Terms & Conditions

Repositories

The Link to the master list
of MaNGOS repositories:
Copyright © getMaNGOS. All rights Reserved.

This website is in no way associated with or endorsed by Blizzard Entertainment®
×
×
  • Create New...