Share via


Initializing a Connection

Note: The Microsoft UDDI SDK is not supported by or included in Microsoft Windows versions after Microsoft Windows Server 7. The Microsoft UDDI V3 SDK is included with Microsoft BizTalk Server. For more information about the Microsoft UDDI V3 SDK, see Microsoft BizTalk Server documentation

This topic describes how to initialize a connection to a UDDI server that specifies all three access points to a UDDI server, and Web proxy information.

Prerequisites and Requirements

The following example requires a computer that has the .NET Framework 2.0 and Visual Studio .Net 2003 or later installed. The example also requires an existing C# project that has a reference to the Microsoft.Uddi assembly.

Example Code

The following example shows how to use the C# programming language to initialize a connection to a UDDI server. For detailed instructions that explain how to develop this example, see the Implementation Steps section.

public UddiConnection InitializeConnection()
{
    string szInquiry = "http://test.uddi.contoso.com/inquire";
    string szPublish = "https://test.uddi.contoso.com/publish";
    string szExtension = "http://test.uddi.contoso.com/extension.asmx";

    string szUsername = null;
    string szPassword = null;

    // Insert code to securely retrieve the user name and password from the user.

    UddiConnection oConnection = null;

    try
    {
        oConnect = new UddiConnection(szInquiry, szPublish, szExtension, szUsername, szPassword);

        System.Net.IWebProxy oProxy = System.Net.WebProxy("http://someproxy:80",true);
        oConnect.AutoGetAuthToken = true;

        oConnect.HttpClient.Proxy = oProxy;

        GetAuthToken oGetToken = new GetAuthToken(szUsername, szPassword);
        oConnect.AuthInfo = oGetToken.Send(oConnect);
        
    }
    catch(InvalidUrlPassedException oUddiEx)
    {
        // Insert exception-handling code.
        return null;
    }
    catch(UddiException oUddiEx)
    {
        // Insert exception-handling code.
        return null;
    }

    return oConnect;
}

Implementation Steps

Complete the following steps to initialize a connection to a UDDI server.

To initialize a connection to a UDDI server

  1. Create a public method that returns a UddiConnection object. Add this method to an existing class in a C# project. This example uses the InitializeConnection method.

    public UddiConnection InitializeConnection()
    {
    }
    
  2. Declare variables to hold the inquiry, publish, and extension URLs.

    public UddiConnection InitializeConnection()
    {
        string szInquiry = null;
        string szPublish = null;
        string szExtension = null;
    }
    
  3. Set the variables to the URLs that are associated with the UDDI server to which the application connects. This example sets the variables to a set of placeholder URLs; replace these with your own UDDI server.

    public UddiConnection InitializeConnection()
    {
        string szInquiry = "http://test.uddi.contoso.com/inquire";
        string szPublish = "https://test.uddi.contoso.com/publish";
        string szExtension = "http://test.uddi.contoso.com/extension.asmx";
    }
    
  4. Optional. Declare variables to hold the user name and password. Then use a secure method to retrieve this information from the user.

    public UddiConnection InitializeConnection()
    {
        string szInquiry = "http://test.uddi.contoso.com/inquire";
        string szPublish = "https://test.uddi.contoso.com/publish";
        string szExtension = "http://test.uddi.contoso.com/extension.asmx";
    
        string szUsername = null;
        string szPassword = null;
    
        // Insert code to securely retrieve the user name and password from the user.
    }
    

    Note

    If the application that you are developing does not perform publishing operations or if the UDDI server to which the application connects uses Windows authentication, skip this step.

  5. Declare a variable for the UddiConnection object. This example uses the variable oConnection.

    public UddiConnection InitializeConnection()
    {
        string szInquiry = "http://test.uddi.contoso.com/inquire";
        string szPublish = "https://test.uddi.contoso.com/publish";
        string szExtension = "http://test.uddi.contoso.com/extension.asmx";
    
        string szUsername = null;
        string szPassword = null;
    
        // Insert code to securely retrieve the user name and password from the user.
    
        UddiConnection oConnection = null;
    }
    
  6. Insert a try block.

    public UddiConnection InitializeConnection()
    {
        string szInquiry = "http://test.uddi.contoso.com/inquire";
        string szPublish = "https://test.uddi.contoso.com/publish";
        string szExtension = "http://test.uddi.contoso.com/extension.asmx";
    
        string szUsername = null;
        string szPassword = null;
    
        // Insert code to securely retrieve the user name and password from the user.
    
        UddiConnection oConnection = null;
    
        try
        {
        }
    }
    
  7. Set the oConnection variable to a new instance of the UddiConnection object by using the UddiConnection constructor and the previously specified string variables.

    Note

    When a user name and password are specified in a constructor for the UddiConnection object, the object will default to UDDI authentication.

    public UddiConnection InitializeConnection()
    {
        string szInquiry = "http://test.uddi.contoso.com/inquire";
        string szPublish = "https://test.uddi.contoso.com/publish";
        string szExtension = "http://test.uddi.contoso.com/extension.asmx";
    
        string szUsername = null;
        string szPassword = null;
    
        // Insert code to securely retrieve the user name and password from the user.
    
        UddiConnection oConnection = null;
    
        try
        {
            oConnect = new UddiConnection(szInquiry, szPublish, szExtension, szUsername, szPassword);
    
        }
    }
    

    If you skipped the step of retrieving the user name and password, use the UddiConnection constructor to set the oConnection variable.

    oConnect = new UddiConnection(szInquiry, szPublish, szExtension);
    
  8. Optional. Set the AutoGetAuthToken property to true, so that the connection will automatically get or refresh the authentication token when it is necessary. You can set this property to false if you want the application to refresh the authentication token manually. Skip this step if you did not retrieve a user name and password.

    public UddiConnection InitializeConnection()
    {
        string szInquiry = "http://test.uddi.contoso.com/inquire";
        string szPublish = "https://test.uddi.contoso.com/publish";
        string szExtension = "http://test.uddi.contoso.com/extension.asmx";
    
        string szUsername = null;
        string szPassword = null;
    
        // Insert code to securely retrieve the user name and password from the user.
    
        UddiConnection oConnection = null;
    
        try
        {
            oConnect = new UddiConnection(szInquiry, szPublish, szExtension, szUsername, szPassword);
            oConnect.AutoGetAuthToken = true;
    
        }
    }
    
  9. Optional. Complete the following steps to provide Web proxy information. Skip these steps if the Internet connection that the application will be using does not have a Web proxy.

    To add Web proxy information

    1. Declare a IWebProxy variable to hold Web proxy information. This example uses the variable oProxy.

      public UddiConnection InitializeConnection()
      {
          string szInquiry = "http://test.uddi.contoso.com/inquire";
          string szPublish = "https://test.uddi.contoso.com/publish";
          string szExtension = "http://test.uddi.contoso.com/extension.asmx";
      
          string szUsername = null;
          string szPassword = null;
      
          // Insert code to securely retrieve the user name and password from the user.
      
          UddiConnection oConnection = null;
      
          try
          {
              oConnect = new UddiConnection(szInquiry, szPublish, szExtension, szUsername, szPassword);
              oConnect.AutoGetAuthToken = true;
      
              System.Net.IWebProxy oProxy = null;
      
          }
      }
      
    2. Use the WebProxy method to create an instance of the IWebProxy object.

      The WebProxy method takes two parameters. The first parameter is a string that specifies the Web proxy location and port. The second parameter is a Boolean value that indicates whether the proxy should be bypassed for local addresses. This example uses http://someproxy:80 and true for the parameters.

      public UddiConnection InitializeConnection()
      {
          string szInquiry = "http://test.uddi.contoso.com/inquire";
          string szPublish = "https://test.uddi.contoso.com/publish";
          string szExtension = "http://test.uddi.contoso.com/extension.asmx";
      
          string szUsername = null;
          string szPassword = null;
      
          // Insert code to securely retrieve the user name and password from the user.
      
          UddiConnection oConnection = null;
      
          try
          {
              oConnect = new UddiConnection(szInquiry, szPublish, szExtension, szUsername, szPassword);
              oConnect.AutoGetAuthToken = true;
      
              System.Net.IWebProxy oProxy = System.Net.WebProxy("http://someproxy:80",true);
      
          }
      }
      
    3. Get a reference to the SoapHttpClientProtocol object by using the HttpClient property of the UddiConnection object. Set the Proxy property of the SoapHttpClientProtocol object to a IWebProxy object. This example uses oProxy for the IWebProxy object.

      public UddiConnection InitializeConnection()
      {
          string szInquiry = "http://test.uddi.contoso.com/inquire";
          string szPublish = "https://test.uddi.contoso.com/publish";
          string szExtension = "http://test.uddi.contoso.com/extension.asmx";
      
          string szUsername = null;
          string szPassword = null;
      
          // Insert code to securely retrieve the user name and password from the user.
      
          UddiConnection oConnection = null;
      
          try
          {
              oConnect = new UddiConnection(szInquiry, szPublish, szExtension, szUsername, szPassword);
      
              System.Net.IWebProxy oProxy = System.Net.WebProxy("http://someproxy:80",true);
              oConnect.AutoGetAuthToken = true;
      
              oConnect.HttpClient.Proxy = oProxy;
      
          }
      }
      
  10. Optional. Add code to test the UddiConnection object. At this point in the process, no connection to the UDDI server has yet been made. This example retrieves an AuthToken object by using the Send method.

    public UddiConnection InitializeConnection()
    {
        string szInquiry = "http://test.uddi.contoso.com/inquire";
        string szPublish = "https://test.uddi.contoso.com/publish";
        string szExtension = "http://test.uddi.contoso.com/extension.asmx";
    
        string szUsername = null;
        string szPassword = null;
    
        // Insert code to securely retrieve the user name and password from the user.
    
        UddiConnection oConnection = null;
    
        try
        {
            oConnect = new UddiConnection(szInquiry, szPublish, szExtension, szUsername, szPassword);
    
            System.Net.IWebProxy oProxy = System.Net.WebProxy("http://someproxy:80",true);
            oConnect.AutoGetAuthToken = true;
    
            oConnect.HttpClient.Proxy = oProxy;
    
            GetAuthToken oGetToken = new GetAuthToken(szUsername, szPassword);
            oConnect.AuthInfo = oGetToken.Send(oConnect);
    
        }
    }
    
  11. Insert catch blocks to catch UddiException, InvalidUrlPassedException, and Exception exceptions.

    public UddiConnection InitializeConnection()
    {
        string szInquiry = "http://test.uddi.contoso.com/inquire";
        string szPublish = "https://test.uddi.contoso.com/publish";
        string szExtension = "http://test.uddi.contoso.com/extension.asmx";
    
        string szUsername = null;
        string szPassword = null;
    
        // Insert code to securely retrieve the user name and password from the user.
    
        UddiConnection oConnection = null;
    
        try
        {
            oConnect = new UddiConnection(szInquiry, szPublish, szExtension, szUsername, szPassword);
    
            System.Net.IWebProxy oProxy = System.Net.WebProxy("http://someproxy:80",true);
            oConnect.AutoGetAuthToken = true;
    
            oConnect.HttpClient.Proxy = oProxy;
    
            GetAuthToken oGetToken = new GetAuthToken(szUsername, szPassword);
            oConnect.AuthInfo = oGetToken.Send(oConnect);
    
        }
        catch(InvalidUrlPassedException oUddiEx)
        {
            // Insert exception-handling code.
            return null;
        }
        catch(UddiException oUddiEx)
        {
            // Insert exception-handling code.
            return null;
        }
        catch(Exception oEx)
        {
            // Insert exception-handling code.
            return null;
        }
    }
    
  12. Return the UddiConnection object.

    public UddiConnection InitializeConnection()
    {
        string szInquiry = "http://test.uddi.contoso.com/inquire";
        string szPublish = "https://test.uddi.contoso.com/publish";
        string szExtension = "http://test.uddi.contoso.com/extension.asmx";
    
        string szUsername = null;
        string szPassword = null;
    
        // Insert code to securely retrieve the user name and password from the user.
    
        UddiConnection oConnection = null;
    
        try
        {
            oConnect = new UddiConnection(szInquiry, szPublish, szExtension, szUsername, szPassword);
    
            System.Net.IWebProxy oProxy = System.Net.WebProxy("http://someproxy:80",true);
            oConnect.AutoGetAuthToken = true;
    
            oConnect.HttpClient.Proxy = oProxy;
    
            GetAuthToken oGetToken = new GetAuthToken(szUsername, szPassword);
            oConnect.AuthInfo = oGetToken.Send(oConnect);
    
        }
        catch(InvalidUrlPassedException oUddiEx)
        {
            // Insert exception-handling code.
            return null;
        }
        catch(UddiException oUddiEx)
        {
            // Insert exception-handling code.
            return null;
        }
        catch(Exception oEx)
        {
            // Insert exception-handling code.
            return null;
        }
    
        return oConnect;
    }
    

See Also

Reference

UddiConnection
IWebProxy
SoapHttpClientProtocol

Send comments about this topic to Microsoft.