Creating a WCF Client

Create a WCF client by building a WCF Client Proxy project, which you can add to any WPF Window Application target.

  1. Under the Project node in the New dialog box, select WCF Client Proxy to start the wizard.
  2. Click Next and complete the wizard, entering or selecting values for the project name and library, the service URL or file name, the proxy namespace and assembly, and the library for the proxy. In the wizard, you can also review the services and data classes defined in the service that you select.

    For the service URL or file name, you can enter or choose files with the WSDL, ASMX, XML, or SVC extension.

    Note: If your development computer is behind a proxy server, the PowerBuilder WCF Client Proxy wizard uses the proxy server settings from Internet Explorer.
  3. Click Finish to create the project object.
  4. Right-click the new project object in the Solution Explorer and select Generate Proxy.
    PowerBuilder loads the WCF client assembly and creates a proxy NVO that represents a class defined by the service.

    If a service has endpoints with different bindings, PowerBuilder .NET generates one proxy NVO for each binding.

    Each generated proxy has one public property, wcfConnectionObject, which is assigned to a default instance of WCFConnection.

  5. (Optional) Change default values of WCFConnection, or create a nondefault instance of WCFConnection, and set all of its binding and binding-related properties.
    • Change specific properties of the WCFConnection object assigned to the wcfConnectionObject property of the generated proxy, such as the endpoint and timeout, as shown in this example:
         ProxyNVO.wcfConnectionObject.EndpointAddress.URL="xxx"
         ProxyNVO.wcfConnectionObject.Timeout="00:05:00"
    • Create a WCFConnection object and manually set all its properties, then assign the object to the wcfConnectionObject property of the generated proxy:
         PBWCF.WCFConnection obj
         obj= create PBWCF.WCFConnection
         obj.EndpointAddress.URL="xxx"
         obj.Timeout="00:10:00"
         obj.BindingType=PBWCF.WCFBindingType.BasicHTTPBinding!
         obj.BasicHTTPBinding=create PBWCF.WCFBasicHTTPBinding
         obj.BasicHttpBinding.PBWCF.TransferMode.Streamed!
         ...
         ProxyNVO.wcfConnectionObject = obj
  6. Call a method of the instance of the proxy NVO.
    You cannot use PowerScript exception objects to catch errors from a WCF service call. You must catch any exceptions using the .NET System.Exception class, as in this example, or by using a class that inherits from System.Exception:
       ns_test_wsdwSoapClient svc
       svc = create ns_test_wsdwSoapClient 
    
       try	
       svc.wcfConnectionObject.ClientCredential.UserName.UserName=“xx” 
       svc.wcfConnectionObject.ClientCredential.UserName.Password=“xxx”  
          string ret
          ret = svc.getProverb()
          messagebox("ok", ret)
       catch (System.Exception ee)
    	     // Error handling
       End try
    
    Note: If your development computer is behind a proxy server, and you do not want the WCF client to use the default proxy server settings from Internet Explorer, you can change the settings with code like this:
     svc.wcfConnectionObject.ProxyServer.UseDefaultWebProxy = false
     svc.wcfConnectionObject.ProxyServer.ProxyAddress =  
       "http://hostname:9090"
    

    Otherwise, you can change the proxy server settings at runtime through an instance of the WCFProxyServer class that you assign to the WCFConnection object instance.

  7. Deploy and run the WPF application with the WCF project.
Related reference
WCFConnection Object