The general way this is done is using an OPC toolkit. There are many toolkits available in the market like FactorySoft which create the complete OPC Server code. You just need to fill in the code for reads/writes, etc. related to the specific protocol you are trying to implement. There are samples and documents avaialble with the toolkit which assist you in doing this.
These toolkits usually can be purchased for a one-time license fee.