Monday, August 11, 2008

Getting to grips with Apache on the Mac - Part 1

First off, lets explain that this is only a first attempt at getting a full Web Service up and running on Leopard (OSX 10.5). Don't expect this to be an in depth explanation of the process, it is only a step by step guide and notes as I do it myself. Being a .Net developer I can find my way around IIS without any problem and moving to Unix is a bit of leap. With luck by the time I've completed this post, both you and I will know a little more than before.

1) Starting the Apache web server on 10.5 is the easy bit, as the software is already included in your installation. Simply go to the System Preferences options from the Apple icon. Select "Sharing" from the "Internet and Network" section. Click the "Web Sharing" on and you should get a HTTP link on the right showing the IP Address of the server.

2) Clicking this link will bring up a default Apache webpage showing
"If you can see this, it means that the installation of the Apache web server software on this system was successful. You may now add content to this directory and replace this page."
Clicking the site http://ipaddress/~username
brings up
"Forbidden You don't have permission to access /~username/ on this server."

3) "So where are all the files then?", I asked myself. Well, after some searching I found the configuration files in the /etc/apache2 directory on the System volume. Get there using the Terminal application and edit the "httpd.conf" file. This contains all the main information information. hostname, ServerAdmin email address, IP Address, etc.
The information in this file indicated that the root directory "INETPUB/wwwroot" in Windows is located in /Library/Webserver/Documents.

4) Editing the DocumentRoot setting in the httpd.conf file moves the home directory to a new location brings up a "readonly" error in vi. The only way around this is to make the editable is to do it with increased permissions. First off I tried to do a "su root" command, only to find that this is disabled by default on my version of OSX. However, you can use the "sudo vi httpd.conf" command to open the config file with read/write access.

5) Using XCode I create a new index.html file with some text and placed it in the required directory.

6) Start/Stop the webservice and browse to the IPAddress of your server and you won't get the correct file displayed, No, for some reason you get the default Apache not configured message. After much head scratching I discovered that it will work fine if you use Local host (i.e. 127.0.0.1) as the IP address in the browser. Why? Who knows, guess its something to do with the configuration in the .conf file. However accessing the file from another browser on the LAN worked fine!

More next time ....

Friday, August 1, 2008

Connecting BDC to SQL WebService

Recently I've been experimenting with the Business Data Connector (BDC) technology available within MOSS. Resources on the Net are generally supportive and I've found that in general it works most of the time. Connecting to Database tables is well supported and although limited, connecting to WebServices is also possible. I have however come up with a limitation that I was unable to get around, that is connecting BDC to a SQL WebService or WCF Service as opposed to a standard ASPX.

Full WCF is simply not supported, however using the basicHTTP protocol can be accomplished with a little bit of text editing of the XML. I was however surprised that the SQL WebSerice caused such an issue for the BDC Editor.

Creating the WebService within SQL is a simple matter of running the following SQL against the NorthWind database:

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetProductsProc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[GetProductsProc]
GO
CREATE PROC dbo.GetProductsProc
AS
SELECT
ProductID,
ProductName,
UnitPrice
FROM
Products
GO

DROP ENDPOINT GetProducts
GO

CREATE ENDPOINT GetProducts
STATE = STARTED
AS HTTP
(
PATH = '/Store',
AUTHENTICATION = (INTEGRATED),
PORTS = (CLEAR),
CLEAR_PORT = 8045,
SITE = '*'
)
FOR SOAP
(
WEBMETHOD 'ProductsList'
(NAME='Northwind.dbo.GetProductsProc'),
BATCHES = DISABLED,
WSDL = DEFAULT,
LOGIN_TYPE = WINDOWS,
DATABASE = 'Northwind',
NAMESPACE = 'http://Northwind/Store'
)
GO


This provides an endpoint on the URL HTTP://localhost:8045/Store?wsdl.

Opening up the BCD Editor (available in the SharePoint SDK) and connecting to the WebService by clicking Add LOB System, Connect to WebService and type in the URL to your SQL WebService.





Click Add WebMethod from the right toolbar and drag the "ProductList" method on to the canvans and click OK. Choose the standard 'WebServiceLobSystem' System Name.






At this point we would create a Finder Instance within the /Entities/Entity0/Method/ProductList/Instances node and click Execute.








However unlike a standard webservice we get the error: AdapterObject is not of RootTypeDescriptor Type. Parameter name: adapterObject.















Following a long investigation I was unable to find a resolution to this issue. It is however all related to the fact that SQL is publishing the return values as an array of System.Objects and not an array of System.String. I'm hoping that the next version of the BCD Editor will work correctly.

Full Microsoft documentation for the BDC is available from :http://msdn.microsoft.com/en-us/library/ms563661.aspx