示例#1
0
        /// <summary>
        /// Create an EQUELLASOAP and login to the EQUELLA server
        /// </summary>
        /// <param name="institutionURL">URL is of the form:  http://myserver/mysint/</param>
        /// <param name="username">User's login name</param>
        /// <param name="password">User's password</param>
        /// <param name="proxyURL">The full URL to a proxy server (if required)</param>
        /// <param name="proxyUsername">The username for the proxy (if required)</param>
        /// <param name="proxyPassword">The password for the proxy (if required)</param>
        public EQUELLASOAP(string institutionURL, string username, string password, string proxyURL, string proxyUsername, string proxyPassword, CookieContainer cookieJar)
        {
            this.institutionURL = institutionURL;

            client          = new SoapService50Ex();
            scrapbookClient = new ScrapbookSoapService.ScrapbookSoapService();

            ////You need to explicitly specify a URL, even if you setup a reference to a WSDL on your own server.
            ////The wsdl returned contains a URL without the institution context, so the setting the URL is required to override this
            client.Url          = institutionURL + "services/SoapService50";
            scrapbookClient.Url = institutionURL + "services/ScrapbookSoapService";

            ////This is important!  it is required to maintain user state between SOAP method invocations
            if (cookieJar == null)
            {
                this.cookieJar = cookieJar;
            }
            else
            {
                this.cookieJar = new CookieContainer();
            }
            client.CookieContainer          = cookieJar;
            scrapbookClient.CookieContainer = cookieJar;

            if (proxyURL != null)
            {
                WebProxy proxy = null;
                if (proxyUsername != null)
                {
                    proxy = new WebProxy(new Uri(proxyURL), false, new string[0], new NetworkCredential(proxyUsername, proxyPassword));
                }
                else
                {
                    proxy = new WebProxy(new Uri(proxyURL));
                }
                client.Proxy          = proxy;
                scrapbookClient.Proxy = proxy;
            }

            //The user must be logged in before any SOAP methods are invoked, otherwise the methods will assume you are an anonymous user
            //and your privileges will be limited.
            if (username != null)
            {
                client.login(username, password);
            }
        }
示例#2
0
        public override void ProcessMessage(SoapMessage message)
        {
            switch (message.Stage)
            {
            case SoapMessageStage.BeforeSerialize:
                break;

            case SoapMessageStage.AfterSerialize:
                newStream.Position = 0;
                Copy(newStream, oldStream);
                break;

            case SoapMessageStage.BeforeDeserialize:
                newStream.Position = 0;
                Copy(oldStream, newStream);

                newStream.Position = 0;
                //TextReader reader = new StreamReader(newStream);
                XElement xml = XElement.Load(newStream);


                if (message is SoapClientMessage)
                {
                    SoapClientMessage clientMessage = (SoapClientMessage)message;
                    if (clientMessage.Client is SoapService50Ex)
                    {
                        SoapService50Ex client = (SoapService50Ex)clientMessage.Client;
                        XNamespace      soap   = "http://schemas.xmlsoap.org/soap/envelope/";
                        client.headerInfo = xml.Element(soap + "Header").Element("equella");
                    }
                }

                newStream.Position = 0;
                break;

            case SoapMessageStage.AfterDeserialize:
                break;
            }
        }