Beispiel #1
0
        internal static void Run(string[] args)
        {
            UDDIClient clerkManager = null;
            Transport  transport    = null;
            UDDIClerk  clerk        = null;

            try
            {
                clerkManager = new UDDIClient("uddi.xml");

                transport = clerkManager.getTransport("uddiv2");

                UDDI_Security_SoapBinding    security = transport.getUDDISecurityService();
                UDDI_Inquiry_SoapBinding     inquiry  = transport.getUDDIInquiryService();
                UDDI_Publication_SoapBinding publish  = transport.getUDDIPublishService();

                clerk = clerkManager.getClerk("uddiv2");

                save_business sb = new save_business();
                get_authToken rq = new get_authToken();
                rq.cred   = "username";
                rq.userID = "username";
                String token = security.get_authToken(rq).authInfo;
                System.Console.WriteLine("Got an auth token...");
                sb.authInfo                      = token;
                sb.businessEntity                = new businessEntity[1];
                sb.businessEntity[0]             = new businessEntity();
                sb.businessEntity[0].name        = new name[] { new name("test business from .net via uddi2 translation", "en") };
                sb.businessEntity[0].description = new description[] { new description("a description", "en") };
                businessDetail detail = publish.save_business(sb);
                System.Console.WriteLine("business saved");
                PrintUDDI <businessDetail> p = new PrintUDDI <businessDetail>();
                Console.Out.WriteLine(p.print(detail));

                save_service ss = new save_service();
                ss.authInfo                       = token;
                ss.businessService                = new businessService[1];
                ss.businessService[0]             = new businessService();
                ss.businessService[0].name        = new name[] { new name("hello world", "en") };
                ss.businessService[0].businessKey = detail.businessEntity[0].businessKey;
                serviceDetail sd = publish.save_service(ss);
                System.Console.WriteLine("service saved");
                PrintUDDI <serviceDetail> p1 = new PrintUDDI <serviceDetail>();
                Console.Out.WriteLine(p1.print(sd));

                save_binding sbd = new save_binding();
                sbd.authInfo                      = token;
                sbd.bindingTemplate               = new bindingTemplate[1];
                sbd.bindingTemplate[0]            = new bindingTemplate();
                sbd.bindingTemplate[0].Item       = new accessPoint("http://localhost", "endPoint");
                sbd.bindingTemplate[0].serviceKey = sd.businessService[0].serviceKey;
                bindingDetail bd = publish.save_binding(sbd);
                System.Console.WriteLine("binding saved");
                PrintUDDI <bindingDetail> p2 = new PrintUDDI <bindingDetail>();
                Console.Out.WriteLine(p2.print(bd));

                save_tModel stm = new save_tModel();
                stm.authInfo       = token;
                stm.tModel         = new tModel[1];
                stm.tModel[0]      = new tModel();
                stm.tModel[0].name = new name("a uddiv2 tmodel", "en");
                tModelDetail td = publish.save_tModel(stm);
                System.Console.WriteLine("tModel saved");
                PrintUDDI <tModelDetail> p3 = new PrintUDDI <tModelDetail>();
                Console.Out.WriteLine(p3.print(td));
            }
            catch (Exception ex)
            {
                while (ex != null)
                {
                    System.Console.WriteLine("Error! " + ex.Message);
                    ex = ex.InnerException;
                }
            }
            finally
            {
                if (transport != null && transport is IDisposable)
                {
                    ((IDisposable)transport).Dispose();
                }
                if (clerk != null)
                {
                    clerk.Dispose();
                }
            }
        }
        /**
         * Registers a UDDI binding template that represents the subscription
         * callback endpoint
         *
         * @param client
         * @param cfg_node_name
         * @param bt - Binding Template
         * @param behavior
         * @return
         * @throws ServiceAlreadyStartedException
         * @throws SecurityException
         * @throws ConfigurationException
         * @throws TransportException
         * @throws DispositionReportFaultMessage
         * @throws RemoteException
         * @throws UnexpectedException
         * @throws RegistrationAbortedException
         * @throws UnableToSignException
         */
        public static bindingTemplate registerBinding(UDDIClient client, String cfg_node_name, bindingTemplate bt, SignatureBehavior behavior)
        {
            log.info("Attempting to register binding " + bt.bindingKey);
            UDDIClerk clerk = client.getClerk(cfg_node_name);
            Transport tp    = client.getTransport(cfg_node_name);
            UDDI_Inquiry_SoapBinding     uddiInquiryService = tp.getUDDIInquiryService();
            UDDI_Publication_SoapBinding uddiPublishService = tp.getUDDIPublishService();


            String token = clerk.getAuthToken(clerk.getUDDINode().getSecurityUrl());

            switch (behavior)
            {
            case SignatureBehavior.AbortIfSigned:
                if (CheckExistingBindingForSignature(bt.bindingKey, uddiInquiryService, token, behavior))
                {
                    throw new RegistrationAbortedException("Aborting, Either the item exists and is signed");
                }
                if (CheckServiceAndParentForSignature(bt.serviceKey, uddiInquiryService, token))
                {
                    throw new RegistrationAbortedException("Aborting, Either the service or busness is signed");
                }
                break;

            case SignatureBehavior.DoNothing:
                break;

            case SignatureBehavior.SignAlways:
                try
                {
                    DigSigUtil ds = new DigSigUtil(client.getClientConfig().getDigitalSignatureConfiguration());
                    bt = (bindingTemplate)ds.signUddiEntity(bt);
                }
                catch (Exception ex)
                {
                    log.error("Unable to sign", ex);
                    throw new UnableToSignException("Unable to sign", ex);
                }

                break;

            case SignatureBehavior.SignOnlyIfParentIsntSigned:
                if (!CheckServiceAndParentForSignature(bt.serviceKey, uddiInquiryService, token))
                {
                    try
                    {
                        DigSigUtil ds = new DigSigUtil(client.getClientConfig().getDigitalSignatureConfiguration());
                        bt = (bindingTemplate)ds.signUddiEntity(bt);
                    }
                    catch (Exception ex)
                    {
                        log.error("Unable to sign", ex);
                        throw new UnableToSignException("Unable to sign", ex);
                    }
                }
                break;
            }
            save_binding sb = new save_binding();

            sb.authInfo        = (token);
            sb.bindingTemplate = new bindingTemplate[] { bt };

            bindingDetail saveBinding = uddiPublishService.save_binding(sb);

            log.info("Binding registered successfully");
            if (saveBinding.bindingTemplate == null || saveBinding.bindingTemplate.Length > 1)
            {
                throw new UnexpectedResponseException("The number of binding templates returned was unexpected, count=" + (saveBinding.bindingTemplate == null ? "none" : saveBinding.bindingTemplate.Length.ToString()));
            }
            return(saveBinding.bindingTemplate[0]);
        }