Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
11,801


I've been doing a lot of WCF lately (mostly in VS) and wanted to share some of my experience and knowledge with my PB brothers and sisters. If you are working with WCF on both ends (client and server) you have the option of using NetTcp instead of Http. NetTcp is faster than Http so you'll want to consider this option if it's available. For more info on the hows and whys ask the internet. I only know enough to be dangerous so let's get to it!

I used PB 12.5.2 for this but any 12.5 version or above should suffice.

The agenda...

1. Create a WCF service in PB.Net that retrieves data from the demo db and create a PDF from it. Return the PDF as a blob.

2. Configure the service with 2 end points: BasicHttp and NetTcp

3. Install Windows Process Activiation Service (WAS)

4. Create a WPF client using PB.Net to call the WCF Service.

5. Create a Win32 client using PB Classic to call the WCF Service.

Create the WCF Service

Open up PB.Net

If you don't have a workspace created go ahead and create one.

Right click on your workspace and add a new target of type WCF Service

Go through the wizard. You can take the defaults if you like but I prefer to put each target in its own folder.

Go ahead and select 'Custom Nonvisual' as the initial object to create.

I like to name the virtual directory something useful too. _wcfservice just doesn't light my fire.

Now create a datawindow that retrieves all columns from the employee table.

Make the where clause where dept_id = :ai_dept_id

Save the datawindow as d_grid

Create a new nvo with two instance variables.

blob ib_pdf

string is_error_msg.

Save it as n_ret. We will use this to return the PDF document

Open the nvo the wizard created for you. It will be called n_customnonvisual if you took the defaults.

Create a function on it called of_create_pdf that takes an integer argument and returns a n_ret (the nvo you created earlier).

Paste the code from the attachment of_create_pdf.txt into your function.

It basically connects to the db, retrieves the data into the datawindow, creates a pdf file, creates a blob from the pdf file, deletes the pdf file on the server and returns the blob as part of n_ret.

Save your nvo and close it.

Open the project file.

Expose your function to create the pdf by checking the box. Rename it if you want to.

Set the Operation Attribute STAOperationBehavior.

Here's an example...

Copy the web service url to the clipboard. You'll need it later.

Configure the WCF Service using the Service Configuration Editor

Locate the config file in your target. It should be the only one with a 'config' extension in your solution explorer.

Right click on it and select 'open with' then click the Add button

Click the ellipse button and navigate to the following file... C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools\SvcConfigEditor.exe

Enter a friendly name to name it and click Ok. You now have the Microsoft SDK WCF service configuration editor in your PB arsenal.

Select it from your list and open your config file.

Right click on the 'Bindings' folder and add a new binding configuration.

Select basicHttpBinding and click Ok.

Increase all values in the general section that have 65536 to something bigger. I chose 1048576.

Change all the zeros in the Reader Quotas section to 1048576 too.

Make the name something meaningful like BasicBindingMax

Create another binding configuration but this time choose netTcpBinding.

Set its values to the same as the basicHttpBinding values.

Now locate your service in the services folder at the top of the tree.

You should see two endpoints in your service. One for basicHttpBinding and one for MexHttpBinding.

Locate the name field in the grid and give each a name so that '(Empty Name)' doesn't show up in the tree.

Set the binding configuration for your basicHttpBinding to the basic binding you just created. Its probably the only option.

Now right click on the EndPoints folder and add a new endpoint.

Set the binding to netTcpBinding

Set the binding configuration to the netTcp one you just created earlier. Again its probably the only option.

Name your netTcp endpoint.

Save your changes and close the config editor.

Here's an example...

Build and deploy your WCF using the project painter.

Install WAS (Windows Process Activation Service)

Go to Control Panel and bring up the add/ remove windows features and install WAS...

Now install .Net 3.5 Framework

Go to Component Services and start the WAS service

Launch IIS Manager (InetMgr)

Create a pdf folder under your WCF Service and give Authenticated Users write access

Select the Default Web Site

Click Advanced Properties

Add net.tcp to the Enabled Protocols property...

Do the same thing for your WCF web service by selecting it and going to Advanced Properties.

Now your ready to test your web service configuration.

Launch the WCF Test Client app ("C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\WcfTestClient.exe")

Point to your web service url from your project file (it should be on your clipboard so just paste it)

You should see both your basicHttp and your netTcp end points exposed...

They won't work because PDFs are too large for the default settings of the WCF Test Client. We just wanted to verify that the end points were exposed.

Now lets create some clients and show some PDFs!

Create a WPF target in PB.Net

Add a window

Add code in the app open event to open the window

Add a new wcf client proxy project that points to your service

Generate the proxy using the proxy project

Save your proxy project changes and close the project painter

Add a button to your window that will be clicked to call your web service

Add a single line edit to capture the dept id, two radio buttons to capture the binding preference Http or NetTcp, and a web browser control to display the PDF

Paste the code from click.txt into the clicked event of your button

This code creates a client proxy, assigns the connection based on the binding selected, increases the buffers to hold a PDF file, calls the service, then displays the PDF using a web browser control

Here's an example of the GUI...

Now run the WPF app and see if it works using  either binding.

Last but not least lets create a Win32 client with PB Classic

Create a regular PB app

Add a window that has a button, sle, two radio buttons and a web browser control

You will need to add the proper registry entries for your service in order for PB to find it

Bruce has covered this very well so I won't go in to that.

Add the PB web service extension to get the soap objects (pbwsclient125.pbx)

Add the code in the attachment win32_click.txt to the clicked event of the button

It should look something like this...

Run the app and see if it works using either binding.

This was a long post and exposed you to several different programs. I hope you got something out of it. I can post the code for all three programs if desired.

Thanks and Good Luck!

Mark

Labels in this area